mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make sure the subscription confirmaion is only sent out once
This commit is contained in:
parent
0d99cfd5ca
commit
506d84c157
2 changed files with 34 additions and 2 deletions
|
@ -180,6 +180,10 @@ module ActionCable
|
|||
@defer_subscription_confirmation
|
||||
end
|
||||
|
||||
def subscription_confirmation_sent?
|
||||
@subscription_confirmation_sent
|
||||
end
|
||||
|
||||
private
|
||||
def delegate_connection_identifiers
|
||||
connection.identifiers.each do |identifier|
|
||||
|
@ -231,8 +235,12 @@ module ActionCable
|
|||
end
|
||||
|
||||
def transmit_subscription_confirmation
|
||||
logger.info "#{self.class.name} is transmitting the subscription confirmation"
|
||||
connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: SUBSCRIPTION_CONFIRMATION_INTERNAL_MESSAGE)
|
||||
unless subscription_confirmation_sent?
|
||||
logger.info "#{self.class.name} is transmitting the subscription confirmation"
|
||||
connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: SUBSCRIPTION_CONFIRMATION_INTERNAL_MESSAGE)
|
||||
|
||||
@subscription_confirmation_sent = true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,6 +10,11 @@ class ActionCable::Channel::StreamTest < ActionCable::TestCase
|
|||
stream_from "test_room_#{@room.id}"
|
||||
end
|
||||
end
|
||||
|
||||
def send_confirmation
|
||||
transmit_subscription_confirmation
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
test "streaming start and stop" do
|
||||
|
@ -53,4 +58,23 @@ class ActionCable::Channel::StreamTest < ActionCable::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "stream_from subscription confirmation should only be sent out once" do
|
||||
EM.run do
|
||||
connection = TestConnection.new
|
||||
connection.stubs(:pubsub).returns EM::Hiredis.connect.pubsub
|
||||
|
||||
channel = ChatChannel.new connection, "test_channel"
|
||||
channel.send_confirmation
|
||||
channel.send_confirmation
|
||||
|
||||
EM.run_deferred_callbacks
|
||||
|
||||
expected = ActiveSupport::JSON.encode "identifier" => "test_channel", "type" => "confirm_subscription"
|
||||
assert_equal expected, connection.last_transmission, "Did not receive subscription confirmation within 0.1s"
|
||||
|
||||
assert_equal 1, connection.transmissions.size
|
||||
EM.stop
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue