Skip to content

Commit

Permalink
Merge pull request #23715 from maclover7/fix-unsubscribe
Browse files Browse the repository at this point in the history
Fix `unsubscribed` server side behavior
  • Loading branch information
matthewd committed Feb 19, 2016
2 parents 042bfb8 + cefcc0f commit 6da571a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
7 changes: 2 additions & 5 deletions actioncable/lib/action_cable/connection/client_socket.rb
Expand Up @@ -132,11 +132,8 @@ def begin_close(reason, code)
@ready_state = CLOSING
@close_params = [reason, code]

if @stream
@stream.shutdown
else
finalize_close
end
@stream.shutdown if @stream
finalize_close
end

def finalize_close
Expand Down
2 changes: 1 addition & 1 deletion actioncable/lib/action_cable/connection/subscriptions.rb
Expand Up @@ -54,7 +54,7 @@ def identifiers
end

def unsubscribe_from_all
subscriptions.each { |id, channel| channel.unsubscribe_from_channel }
subscriptions.each { |id, channel| remove_subscription(channel) }
end

protected
Expand Down
4 changes: 4 additions & 0 deletions actioncable/test/client/echo_channel.rb
Expand Up @@ -3,6 +3,10 @@ def subscribed
stream_from "global"
end

def unsubscribed
'Goodbye from EchoChannel!'
end

def ding(data)
transmit(dong: data['message'])
end
Expand Down
21 changes: 21 additions & 0 deletions actioncable/test/client_test.rb
Expand Up @@ -199,4 +199,25 @@ def test_disappearing_client
c.close # disappear before read
end
end

def test_unsubscribe_client
with_puma_server do |port|
app = ActionCable.server
identifier = JSON.dump(channel: 'EchoChannel')

c = faye_client(port)
c.send_message command: 'subscribe', identifier: identifier
assert_equal({"identifier"=>"{\"channel\":\"EchoChannel\"}", "type"=>"confirm_subscription"}, c.read_message)
assert_equal(1, app.connections.count)
assert(app.remote_connections.where(identifier: identifier))

channel = app.connections.first.subscriptions.send(:subscriptions).first[1]
channel.expects(:unsubscribed)
c.close
sleep 0.1 # Data takes a moment to process

# All data is removed: No more connection or subscription information!
assert_equal(0, app.connections.count)
end
end
end

0 comments on commit 6da571a

Please sign in to comment.