Commit 3c65a1df authored by Wandenberg's avatar Wandenberg

try to make the test more stable

parent 4516ca59
...@@ -26,6 +26,7 @@ describe "Events channel" do ...@@ -26,6 +26,7 @@ describe "Events channel" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
...@@ -33,6 +34,7 @@ describe "Events channel" do ...@@ -33,6 +34,7 @@ describe "Events channel" do
end end
end end
end end
end
it "should send an event when a channel is deleted" do it "should send an event when a channel is deleted" do
channel = 'ch_test_send_event_channel_deleted' channel = 'ch_test_send_event_channel_deleted'
...@@ -43,7 +45,6 @@ describe "Events channel" do ...@@ -43,7 +45,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers
sub_1.stream do |chunk| sub_1.stream do |chunk|
...@@ -51,6 +52,7 @@ describe "Events channel" do ...@@ -51,6 +52,7 @@ describe "Events channel" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
pub_2 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").delete head: headers pub_2 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").delete head: headers
pub_2.callback do pub_2.callback do
expect(pub_2).to be_http_status(200).without_body expect(pub_2).to be_http_status(200).without_body
...@@ -58,6 +60,8 @@ describe "Events channel" do ...@@ -58,6 +60,8 @@ describe "Events channel" do
end end
end end
end end
end
end
it "should send an event when a channel is collected by inactivity" do it "should send an event when a channel is collected by inactivity" do
channel = 'ch_test_send_event_channel_collected' channel = 'ch_test_send_event_channel_collected'
...@@ -68,7 +72,6 @@ describe "Events channel" do ...@@ -68,7 +72,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}", inactivity_timeout: 40).get head: headers sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}", inactivity_timeout: 40).get head: headers
sub_1.stream do |chunk| sub_1.stream do |chunk|
...@@ -78,6 +81,7 @@ describe "Events channel" do ...@@ -78,6 +81,7 @@ describe "Events channel" do
end end
end end
end end
end
it "should send an event when a client subscribe to a channel" do it "should send an event when a client subscribe to a channel" do
channel = 'ch_test_send_event_client_subscribed' channel = 'ch_test_send_event_client_subscribed'
...@@ -88,7 +92,6 @@ describe "Events channel" do ...@@ -88,7 +92,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers
sub_1.stream do |chunk| sub_1.stream do |chunk|
...@@ -96,10 +99,13 @@ describe "Events channel" do ...@@ -96,10 +99,13 @@ describe "Events channel" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers
end end
end end
end end
end
end
it "should send an event when a websocket client subscribe to a channel" do it "should send an event when a websocket client subscribe to a channel" do
channel = 'ch_test_send_event_websocket_client_subscribed' channel = 'ch_test_send_event_websocket_client_subscribed'
...@@ -110,7 +116,6 @@ describe "Events channel" do ...@@ -110,7 +116,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
sub_1 = WebSocket::EventMachine::Client.connect(uri: "ws://#{nginx_host}:#{nginx_port}/sub/#{conf.events_channel_id}") sub_1 = WebSocket::EventMachine::Client.connect(uri: "ws://#{nginx_host}:#{nginx_port}/sub/#{conf.events_channel_id}")
sub_1.onmessage do |text, type| sub_1.onmessage do |text, type|
...@@ -118,10 +123,13 @@ describe "Events channel" do ...@@ -118,10 +123,13 @@ describe "Events channel" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
ws = WebSocket::EventMachine::Client.connect(uri: "ws://#{nginx_host}:#{nginx_port}/sub/#{channel}") ws = WebSocket::EventMachine::Client.connect(uri: "ws://#{nginx_host}:#{nginx_port}/sub/#{channel}")
end end
end end
end end
end
end
it "should send an event when a long-polling client subscribe to a channel" do it "should send an event when a long-polling client subscribe to a channel" do
channel = 'ch_test_send_event_client_subscribed' channel = 'ch_test_send_event_client_subscribed'
...@@ -132,7 +140,6 @@ describe "Events channel" do ...@@ -132,7 +140,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
response = '' response = ''
sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers
...@@ -142,10 +149,13 @@ describe "Events channel" do ...@@ -142,10 +149,13 @@ describe "Events channel" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers
end end
end end
end end
end
end
it "should send an event when a client unsubscribe to a channel by timeout" do it "should send an event when a client unsubscribe to a channel by timeout" do
channel = 'ch_test_send_event_client_unsubscribed' channel = 'ch_test_send_event_client_unsubscribed'
...@@ -174,12 +184,15 @@ describe "Events channel" do ...@@ -174,12 +184,15 @@ describe "Events channel" do
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers sub_1 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{channel}").get head: headers
EM.add_timer(0.5) do
sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers sub_2 = EventMachine::HttpRequest.new("#{nginx_address}/sub/#{conf.events_channel_id}").get head: headers
sub_2.stream do |chunk| sub_2.stream do |chunk|
expect(chunk).to eql(%(text: {"type": "client_unsubscribed", "channel": "#{channel}"}\nchannel: #{conf.events_channel_id})) expect(chunk).to eql(%(text: {"type": "client_unsubscribed", "channel": "#{channel}"}\nchannel: #{conf.events_channel_id}))
EventMachine.stop EventMachine.stop
end end
end
EM.add_timer(1) do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").delete head: headers pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").delete head: headers
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).without_body expect(pub_1).to be_http_status(200).without_body
...@@ -187,6 +200,7 @@ describe "Events channel" do ...@@ -187,6 +200,7 @@ describe "Events channel" do
end end
end end
end end
end
it "should never collect the events channel by inactivity" do it "should never collect the events channel by inactivity" do
channel = 'ch_test_not_collect_events_channel' channel = 'ch_test_not_collect_events_channel'
...@@ -197,7 +211,6 @@ describe "Events channel" do ...@@ -197,7 +211,6 @@ describe "Events channel" do
pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body pub_1 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").post head: headers, body: body
pub_1.callback do pub_1.callback do
expect(pub_1).to be_http_status(200).with_body expect(pub_1).to be_http_status(200).with_body
end
pub_2 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").get head: headers pub_2 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").get head: headers
pub_2.callback do pub_2.callback do
...@@ -207,7 +220,6 @@ describe "Events channel" do ...@@ -207,7 +220,6 @@ describe "Events channel" do
expect(response["published_messages"].to_i).to eql(1) expect(response["published_messages"].to_i).to eql(1)
expect(response["stored_messages"].to_i).to eql(1) expect(response["stored_messages"].to_i).to eql(1)
expect(response["subscribers"].to_i).to eql(0) expect(response["subscribers"].to_i).to eql(0)
end
pub_3 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers pub_3 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers
pub_3.callback do pub_3.callback do
...@@ -218,12 +230,13 @@ describe "Events channel" do ...@@ -218,12 +230,13 @@ describe "Events channel" do
expect(response["stored_messages"].to_i).to eql(1) expect(response["stored_messages"].to_i).to eql(1)
expect(response["subscribers"].to_i).to eql(0) expect(response["subscribers"].to_i).to eql(0)
end end
end
end
EM.add_timer(35) do EM.add_timer(35) do
pub_4 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").get head: headers pub_4 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{channel}").get head: headers
pub_4.callback do pub_4.callback do
expect(pub_4).to be_http_status(404).without_body expect(pub_4).to be_http_status(404).without_body
end
pub_5 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers pub_5 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers
pub_5.callback do pub_5.callback do
...@@ -234,6 +247,7 @@ describe "Events channel" do ...@@ -234,6 +247,7 @@ describe "Events channel" do
expect(response["stored_messages"].to_i).to eql(1) expect(response["stored_messages"].to_i).to eql(1)
expect(response["subscribers"].to_i).to eql(0) expect(response["subscribers"].to_i).to eql(0)
end end
end
EM.add_timer(35) do EM.add_timer(35) do
pub_6 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers pub_6 = EventMachine::HttpRequest.new("#{nginx_address}/pub?id=#{conf.events_channel_id}").get head: headers
...@@ -457,4 +471,3 @@ describe "Events channel" do ...@@ -457,4 +471,3 @@ describe "Events channel" do
end end
end end
end end
#TODO add docs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment