aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/channel/stream_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2016-01-27 14:34:14 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2016-01-27 14:34:14 +0100
commit82885325e04d78fb7ec608a4670164d842d23078 (patch)
treeccc4bdf086f9c8d54c40a38213787e212da1af2b /actioncable/test/channel/stream_test.rb
parent92039d7c7bacfe5747f96047e80f0e8ceb481f62 (diff)
parent9ea7aa84d16d99fd32ed1877e3fd6631a41e7042 (diff)
downloadrails-82885325e04d78fb7ec608a4670164d842d23078.tar.gz
rails-82885325e04d78fb7ec608a4670164d842d23078.tar.bz2
rails-82885325e04d78fb7ec608a4670164d842d23078.zip
Merge pull request #23277 from rails/revert-23152-actioncable-concurrent
Revert "Eliminate the EventMachine dependency"
Diffstat (limited to 'actioncable/test/channel/stream_test.rb')
-rw-r--r--actioncable/test/channel/stream_test.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/actioncable/test/channel/stream_test.rb b/actioncable/test/channel/stream_test.rb
index 947efd96d4..3fa2b291b7 100644
--- a/actioncable/test/channel/stream_test.rb
+++ b/actioncable/test/channel/stream_test.rb
@@ -31,7 +31,9 @@ class ActionCable::Channel::StreamTest < ActionCable::TestCase
test "stream_for" do
run_in_eventmachine do
connection = TestConnection.new
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("action_cable:channel:stream_test:chat:Room#1-Campfire", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
+ EM.next_tick do
+ connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("action_cable:channel:stream_test:chat:Room#1-Campfire", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
+ end
channel = ChatChannel.new connection, ""
channel.stream_for Room.new(1)
@@ -39,35 +41,39 @@ class ActionCable::Channel::StreamTest < ActionCable::TestCase
end
test "stream_from subscription confirmation" do
- run_in_eventmachine do
+ EM.run do
connection = TestConnection.new
ChatChannel.new connection, "{id: 1}", { id: 1 }
assert_nil connection.last_transmission
- wait_for_async
+ EM::Timer.new(0.1) do
+ expected = ActiveSupport::JSON.encode "identifier" => "{id: 1}", "type" => "confirm_subscription"
+ connection.transmit(expected)
- expected = ActiveSupport::JSON.encode "identifier" => "{id: 1}", "type" => "confirm_subscription"
- connection.transmit(expected)
+ assert_equal expected, connection.last_transmission, "Did not receive subscription confirmation within 0.1s"
- assert_equal expected, connection.last_transmission, "Did not receive subscription confirmation within 0.1s"
+ EM.run_deferred_callbacks
+ EM.stop
+ end
end
end
test "subscription confirmation should only be sent out once" do
- run_in_eventmachine do
+ EM.run do
connection = TestConnection.new
channel = ChatChannel.new connection, "test_channel"
channel.send_confirmation
channel.send_confirmation
- wait_for_async
+ 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"
assert_equal 1, connection.transmissions.size
+ EM.stop
end
end