1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
require 'spec_helper'
describe "Subscriber Connection Cleanup" do
let(:config) do
{
:subscriber_connection_ttl => '17s',
:header_template => 'HEADER_TEMPLATE',
:footer_template => 'FOOTER_TEMPLATE',
:ping_message_interval => '3s'
}
end
it "should disconnect the subscriber after the configured connection ttl be reached" do
channel = 'ch_test_subscriber_connection_timeout'
nginx_run_server(config.merge(:ping_message_interval => nil), :timeout => 25) do |conf|
start = Time.now
response = ''
EventMachine.run do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s, :inactivity_timeout => 20).get :head => headers
sub.stream do |chunk|
response += chunk
expect(response).to include(conf.header_template)
end
sub.callback do
stop = Time.now
expect(time_diff_sec(start, stop)).to be_in_the_interval(17, 17.5)
expect(response).to include(conf.footer_template)
EventMachine.stop
end
end
end
end
it "should disconnect the subscriber after the configured connection ttl be reached with ping message" do
channel = 'ch_test_subscriber_connection_timeout_with_ping_message'
nginx_run_server(config.merge(:header_template => nil, :footer_template => nil), :timeout => 25) do |conf|
start = Time.now
chunks_received = 0
EventMachine.run do
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub.stream do |chunk|
chunks_received += 1
end
sub.callback do
stop = Time.now
expect(time_diff_sec(start, stop)).to be_in_the_interval(17, 17.5)
expect(chunks_received).to be_eql(5)
EventMachine.stop
end
end
end
end
it "should disconnect each subscriber after the configured connection ttl be reached starting when it connects" do
channel = 'ch_test_multiple_subscribers_connection_timeout'
nginx_run_server(config.merge(:subscriber_connection_ttl => '5s', :ping_message_interval => nil), :timeout => 25) do |conf|
EventMachine.run do
response_1 = ''
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_1.stream do |chunk|
response_1 += chunk
expect(response_1).to include(conf.header_template)
end
sub_1.callback do
expect(response_1).to include(conf.footer_template)
end
sleep(2)
response_2 = ''
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_2.stream do |chunk|
response_2 += chunk
expect(response_2).to include(conf.header_template)
end
sub_2.callback do
expect(response_2).to include(conf.footer_template)
response_4 = ''
sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_4.stream do |chunk|
response_4 += chunk
expect(response_4).to include(conf.header_template)
end
sub_4.callback do
expect(response_4).to include(conf.footer_template)
EventMachine.stop
end
end
sleep(6)
response_3 = ''
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_3.stream do |chunk|
response_3 += chunk
expect(response_3).to include(conf.header_template)
end
sub_3.callback do
expect(response_3).to include(conf.footer_template)
end
end
end
end
end
|