Commit f517ae57 authored by Wandenberg's avatar Wandenberg

tests refactor to be possible execute them with multiple workers on nginx

parent a48ca949
require 'spec_helper' require 'spec_helper'
describe "Cleanup Memory" do describe "Cleanup Memory" do
workers = 1
old_cld_trap = nil old_cld_trap = nil
before do before do
workers = ENV['NGINX_WORKERS']
ENV['NGINX_WORKERS'] = '1'
old_cld_trap = Signal.trap("CLD", "IGNORE") old_cld_trap = Signal.trap("CLD", "IGNORE")
end end
after do after do
ENV['NGINX_WORKERS'] = workers
Signal.trap("CLD", old_cld_trap) Signal.trap("CLD", old_cld_trap)
end end
...@@ -576,13 +572,13 @@ describe "Cleanup Memory" do ...@@ -576,13 +572,13 @@ describe "Cleanup Memory" do
pub.callback do pub.callback do
pub.should be_http_status(200).with_body pub.should be_http_status(200).with_body
resp_1 = JSON.parse(pub.response) resp_1 = JSON.parse(pub.response)
resp_1["by_worker"].count.should eql(1) resp_1["by_worker"].count.should eql(conf.workers)
pid = resp_1["by_worker"][0]['pid'].to_i pids = resp_1["by_worker"].map{ |info| info['pid'].to_i }
# send kill signal # send kill signal
`kill -9 #{ pid } > /dev/null 2>&1` pids.each{ |pid| `kill -9 #{ pid } > /dev/null 2>&1` }
while `ps -p #{ pid } > /dev/null 2>&1; echo $?`.to_i == 0 while pids.all?{ |pid| `ps -p #{ pid } > /dev/null 2>&1; echo $?`.to_i == 0 }
sleep(0.1) sleep(0.1)
end end
...@@ -600,13 +596,13 @@ describe "Cleanup Memory" do ...@@ -600,13 +596,13 @@ describe "Cleanup Memory" do
pub.callback do pub.callback do
pub.should be_http_status(200).with_body pub.should be_http_status(200).with_body
resp_1 = JSON.parse(pub.response) resp_1 = JSON.parse(pub.response)
resp_1["by_worker"].count.should eql(1) resp_1["by_worker"].count.should eql(conf.workers)
pid = resp_1["by_worker"][0]['pid'].to_i pids = resp_1["by_worker"].map{ |info| info['pid'].to_i }
# send reload signal # send reload signal
`#{ nginx_executable } -c #{ conf.configuration_filename } -s reload > /dev/null 2>&1` pids.each{ |pid| `#{ nginx_executable } -c #{ conf.configuration_filename } -s reload > /dev/null 2>&1` }
while `ps -p #{ pid } > /dev/null 2>&1; echo $?`.to_i == 0 while pids.all?{ |pid| `ps -p #{ pid } > /dev/null 2>&1; echo $?`.to_i == 0 }
sleep(0.1) sleep(0.1)
end end
......
require 'spec_helper' require 'spec_helper'
describe "Send Signals" do describe "Send Signals" do
workers = 1
old_cld_trap = nil old_cld_trap = nil
before do before do
workers = ENV['NGINX_WORKERS']
ENV['NGINX_WORKERS'] = '1'
old_cld_trap = Signal.trap("CLD", "IGNORE") old_cld_trap = Signal.trap("CLD", "IGNORE")
end end
after do after do
ENV['NGINX_WORKERS'] = workers
Signal.trap("CLD", old_cld_trap) Signal.trap("CLD", old_cld_trap)
end end
...@@ -18,6 +14,7 @@ describe "Send Signals" do ...@@ -18,6 +14,7 @@ describe "Send Signals" do
{ {
:master_process => 'on', :master_process => 'on',
:daemon => 'on', :daemon => 'on',
:workers => 1,
:header_template => 'HEADER', :header_template => 'HEADER',
:footer_template => 'FOOTER', :footer_template => 'FOOTER',
:message_ttl => '60s', :message_ttl => '60s',
...@@ -227,7 +224,7 @@ describe "Send Signals" do ...@@ -227,7 +224,7 @@ describe "Send Signals" do
nginx_run_server(config, :timeout => 10) do |conf| nginx_run_server(config, :timeout => 10) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
# check statistics # check statistics
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_1.callback do pub_1.callback do
......
...@@ -4,6 +4,7 @@ module NginxConfiguration ...@@ -4,6 +4,7 @@ module NginxConfiguration
:disable_start_stop_server => false, :disable_start_stop_server => false,
:master_process => 'on', :master_process => 'on',
:daemon => 'on', :daemon => 'on',
:workers => 2,
:gzip => 'off', :gzip => 'off',
...@@ -67,12 +68,12 @@ module NginxConfiguration ...@@ -67,12 +68,12 @@ module NginxConfiguration
def self.template_configuration def self.template_configuration
%( %(
pid <%= pid_file %>; pid <%= pid_file %>;
error_log <%= error_log %> debug; error_log <%= error_log %> info;
# Development Mode # Development Mode
master_process <%= master_process %>; master_process <%= master_process %>;
daemon <%= daemon %>; daemon <%= daemon %>;
worker_processes <%= nginx_workers %>; worker_processes <%= workers %>;
worker_rlimit_core 2500M; worker_rlimit_core 2500M;
working_directory <%= File.join(nginx_tests_tmp_dir, "cores", config_id) %>; working_directory <%= File.join(nginx_tests_tmp_dir, "cores", config_id) %>;
debug_points abort; debug_points abort;
......
...@@ -450,20 +450,16 @@ describe "Publisher Properties" do ...@@ -450,20 +450,16 @@ describe "Publisher Properties" do
sub_2.stream do |chunk| sub_2.stream do |chunk|
resp_2 += chunk resp_2 += chunk
end end
sub_2.callback do
EM.add_timer(2) do
resp_1.should eql("<script>p(1,'channel_id_inside_if_block','published message');</script>") resp_1.should eql("<script>p(1,'channel_id_inside_if_block','published message');</script>")
resp_2.should eql("<script>p(1,'test_channel_id_inside_if_block','published message');</script>") resp_2.should eql("<script>p(1,'test_channel_id_inside_if_block','published message');</script>")
EventMachine.stop EventMachine.stop
end end
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub2?id=' + channel.to_s).post :head => headers, :body => body EM.add_timer(0.5) do
pub_1.callback do post_to('/pub2?id=' + channel.to_s, headers, body)
pub_1.should be_http_status(200) post_to('/pub2?id=' + channel.to_s + '&test=1', headers, body)
end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub2?id=' + channel.to_s + '&test=1').post :head => headers, :body => body
pub_2.callback do
pub_2.should be_http_status(200)
end end
end end
end end
...@@ -538,7 +534,7 @@ describe "Publisher Properties" do ...@@ -538,7 +534,7 @@ describe "Publisher Properties" do
nginx_run_server(config.merge(:gzip => "on"), :timeout => 5) do |conf| nginx_run_server(config.merge(:gzip => "on"), :timeout => 5) do |conf|
EventMachine.run do EventMachine.run do
#create channel #create channel
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).get :head => headers.merge({'accept' => 'application/json', 'accept-encoding' => 'gzip, compressed'}), :decoding => false pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel).get :head => headers.merge({'accept' => 'application/json', 'accept-encoding' => 'gzip, compressed'}), :decoding => false
pub.stream do |chunk| pub.stream do |chunk|
...@@ -610,7 +606,9 @@ describe "Publisher Properties" do ...@@ -610,7 +606,9 @@ describe "Publisher Properties" do
EM.add_periodic_timer(0.5) { EventMachine.stop if messages >= 3 } EM.add_periodic_timer(0.5) { EventMachine.stop if messages >= 3 }
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + '_1/' + channel.to_s + '_2/' + channel.to_s + '_3').post :head => headers, :body => body EM.add_timer(0.5) do
post_to('/pub?id=' + channel.to_s + '_1/' + channel.to_s + '_2/' + channel.to_s + '_3', headers, body)
end
end end
end end
end end
...@@ -945,6 +943,7 @@ describe "Publisher Properties" do ...@@ -945,6 +943,7 @@ describe "Publisher Properties" do
resp_2.should eql("{\"id\":\"-2\", \"channel\":\"test_delete_channels_whith_subscribers_2\", \"text\":\"Channel deleted\"}FOOTER") resp_2.should eql("{\"id\":\"-2\", \"channel\":\"test_delete_channels_whith_subscribers_2\", \"text\":\"Channel deleted\"}FOOTER")
end end
EM.add_timer(0.5) do
stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
stats.callback do stats.callback do
stats.should be_http_status(200).with_body stats.should be_http_status(200).with_body
...@@ -952,7 +951,9 @@ describe "Publisher Properties" do ...@@ -952,7 +951,9 @@ describe "Publisher Properties" do
response["subscribers"].to_i.should eql(2) response["subscribers"].to_i.should eql(2)
response["channels"].to_i.should eql(2) response["channels"].to_i.should eql(2)
end end
end
EM.add_timer(1.5) do
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s).delete :head => headers
pub_1.callback do pub_1.callback do
pub_1.should be_http_status(200).without_body pub_1.should be_http_status(200).without_body
...@@ -964,6 +965,7 @@ describe "Publisher Properties" do ...@@ -964,6 +965,7 @@ describe "Publisher Properties" do
pub_2.should be_http_status(200).without_body pub_2.should be_http_status(200).without_body
pub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.") pub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Channel deleted.")
end end
end
EM.add_timer(5) do EM.add_timer(5) do
stats_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'} stats_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => {'accept' => 'application/json'}
......
...@@ -22,7 +22,7 @@ describe "Publisher Publishing Messages" do ...@@ -22,7 +22,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body publish_message_inline(channel, headers, body)
end end
end end
end end
...@@ -39,7 +39,9 @@ describe "Publisher Publishing Messages" do ...@@ -39,7 +39,9 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).put :head => headers, :body => body, :timeout => 30 EM.add_timer(0.5) do
EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).put :head => headers, :body => body, :timeout => 30
end
end end
end end
end end
...@@ -71,7 +73,7 @@ describe "Publisher Publishing Messages" do ...@@ -71,7 +73,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body publish_message_inline(channel, headers, body)
end end
end end
end end
...@@ -207,7 +209,7 @@ describe "Publisher Publishing Messages" do ...@@ -207,7 +209,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers.merge('Event-Id' => event_id), :body => body publish_message_inline(channel, headers.merge('Event-Id' => event_id), body)
end end
end end
end end
...@@ -230,7 +232,7 @@ describe "Publisher Publishing Messages" do ...@@ -230,7 +232,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers.merge('Event-type' => event_type), :body => body publish_message_inline(channel, headers.merge('Event-type' => event_type), body)
end end
end end
end end
...@@ -253,7 +255,7 @@ describe "Publisher Publishing Messages" do ...@@ -253,7 +255,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers.merge('Event-Ids' => event_id), :body => body publish_message_inline(channel, headers.merge('Event-Ids' => event_id), body)
end end
EventMachine.run do EventMachine.run do
...@@ -267,7 +269,7 @@ describe "Publisher Publishing Messages" do ...@@ -267,7 +269,7 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers.merge('Event-I' => event_id), :body => body publish_message_inline(channel, headers.merge('Event-I' => event_id), body)
end end
end end
end end
...@@ -294,7 +296,7 @@ describe "Publisher Publishing Messages" do ...@@ -294,7 +296,7 @@ describe "Publisher Publishing Messages" do
end end
now = Time.now now = Time.now
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body publish_message_inline(channel, headers, body)
end end
end end
end end
...@@ -323,8 +325,8 @@ describe "Publisher Publishing Messages" do ...@@ -323,8 +325,8 @@ describe "Publisher Publishing Messages" do
EventMachine.stop EventMachine.stop
end end
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body publish_message_inline(channel, headers, body)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body publish_message_inline(channel, headers, body)
end end
end end
end end
......
...@@ -19,23 +19,34 @@ RSpec.configure do |config| ...@@ -19,23 +19,34 @@ RSpec.configure do |config|
config.order = "random" config.order = "random"
end end
def publish_message_inline(channel, headers, body, &block) def publish_message_inline(channel, headers, body, delay=0.01, &block)
EM.add_timer(delay) do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub.callback do pub.callback do
pub.should be_http_status(200) pub.should be_http_status(200)
block.call unless block.nil? block.call(pub) unless block.nil?
end
end end
pub
end end
def publish_message(channel, headers, body) def publish_message(channel, headers, body)
EventMachine.run do http = Net::HTTP.new(nginx_host, nginx_port)
pub = publish_message_inline(channel, headers, body) do req = Net::HTTP::Post.new("/pub?id=#{channel}", headers)
response = JSON.parse(pub.response) req.body = body
response["channel"].to_s.should eql(channel) res = http.request(req)
EventMachine.stop content = res.body
end if res.get_fields("content-encoding").to_a.include?("gzip")
content = Zlib::GzipReader.new(StringIO.new(content)).read
end end
response = JSON.parse(content)
response["channel"].to_s.should eql(channel)
end
def post_to(path, headers, body)
http = Net::HTTP.new(nginx_host, nginx_port)
req = Net::HTTP::Post.new(path, headers)
req.body = body
http.request(req)
end end
def create_channel_by_subscribe(channel, headers, timeout=60, &block) def create_channel_by_subscribe(channel, headers, timeout=60, &block)
......
...@@ -43,10 +43,10 @@ describe "Subscriber Properties" do ...@@ -43,10 +43,10 @@ describe "Subscriber Properties" do
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {'Event-Id' => 'event 1'}, 'msg 1') publish_message(channel, {'Event-Id' => 'event 1'}, 'msg 1')
publish_message_inline(channel, {'Event-Id' => 'event 2'}, 'msg 2') publish_message(channel, {'Event-Id' => 'event 2'}, 'msg 2')
publish_message_inline(channel, {}, 'msg 3') publish_message(channel, {}, 'msg 3')
publish_message_inline(channel, {'Event-Id' => 'event 3'}, 'msg 4') publish_message(channel, {'Event-Id' => 'event 3'}, 'msg 4')
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'Last-Event-Id' => 'event 2'}) sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'Last-Event-Id' => 'event 2'})
sub.stream do |chunk| sub.stream do |chunk|
...@@ -189,8 +189,10 @@ describe "Subscriber Properties" do ...@@ -189,8 +189,10 @@ describe "Subscriber Properties" do
end end
end end
publish_message_inline(channel_1.to_s, headers, body) EM.add_timer(0.5) do
publish_message_inline(channel_2.to_s, headers, body) publish_message(channel_1.to_s, headers, body)
publish_message(channel_2.to_s, headers, body)
end
end end
end end
end end
...@@ -216,6 +218,7 @@ describe "Subscriber Properties" do ...@@ -216,6 +218,7 @@ describe "Subscriber Properties" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).delete :head => headers
pub.callback do pub.callback do
pub.should be_http_status(200).without_body pub.should be_http_status(200).without_body
...@@ -224,6 +227,7 @@ describe "Subscriber Properties" do ...@@ -224,6 +227,7 @@ describe "Subscriber Properties" do
end end
end end
end end
end
it "should accept a callback parameter to be used with JSONP" do it "should accept a callback parameter to be used with JSONP" do
channel = 'ch_test_return_message_using_function_name_specified_in_callback_parameter' channel = 'ch_test_return_message_using_function_name_specified_in_callback_parameter'
...@@ -252,8 +256,8 @@ describe "Subscriber Properties" do ...@@ -252,8 +256,8 @@ describe "Subscriber Properties" do
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {'Event-Id' => 'event_id'}, body) publish_message(channel, {'Event-Id' => 'event_id'}, body)
publish_message_inline(channel, {}, body + "1") publish_message(channel, {}, body + "1")
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b2' + '?callback=' + callback_function_name).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b2' + '?callback=' + callback_function_name).get :head => headers
sub_1.callback do sub_1.callback do
......
...@@ -49,7 +49,7 @@ describe "Subscriber Properties" do ...@@ -49,7 +49,7 @@ describe "Subscriber Properties" do
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")}) sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers.merge({'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")})
sub_1.callback do sub_1.callback do
...@@ -71,7 +71,7 @@ describe "Subscriber Properties" do ...@@ -71,7 +71,7 @@ describe "Subscriber Properties" do
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers.merge({'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")}) sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => headers.merge({'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")})
sub_1.callback do sub_1.callback do
sub_1.response.should eql("#{callback_function_name}([#{body}]);") sub_1.response.should eql("#{callback_function_name}([#{body}]);")
...@@ -89,8 +89,8 @@ describe "Subscriber Properties" do ...@@ -89,8 +89,8 @@ describe "Subscriber Properties" do
nginx_run_server(config) do |conf| nginx_run_server(config) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {'Event-Id' => 'event_id'}, body) publish_message(channel, {'Event-Id' => 'event_id'}, body)
publish_message_inline(channel, {}, body + "1") publish_message(channel, {}, body + "1")
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b2' + '?callback=' + callback_function_name).get :head => headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b2' + '?callback=' + callback_function_name).get :head => headers
sub_1.callback do sub_1.callback do
...@@ -120,7 +120,7 @@ describe "Subscriber Properties" do ...@@ -120,7 +120,7 @@ describe "Subscriber Properties" do
nginx_run_server(config.merge({:content_type => "anything/value"})) do |conf| nginx_run_server(config.merge({:content_type => "anything/value"})) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
sent_headers = headers.merge({'accept' => 'otherknown/value'}) sent_headers = headers.merge({'accept' => 'otherknown/value'})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => sent_headers sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '?callback=' + callback_function_name).get :head => sent_headers
sub_1.callback do sub_1.callback do
...@@ -138,7 +138,7 @@ describe "Subscriber Properties" do ...@@ -138,7 +138,7 @@ describe "Subscriber Properties" do
nginx_run_server(config.merge({:gzip => "on"})) do |conf| nginx_run_server(config.merge({:gzip => "on"})) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {}, body) publish_message(channel, {}, body)
sent_headers = headers.merge({'accept-encoding' => 'gzip, compressed', 'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")}) sent_headers = headers.merge({'accept-encoding' => 'gzip, compressed', 'If-Modified-Since' => Time.at(0).utc.strftime("%a, %d %b %Y %T %Z")})
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers, :decoding => false sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => sent_headers, :decoding => false
......
...@@ -365,12 +365,14 @@ describe "Subscriber Properties" do ...@@ -365,12 +365,14 @@ describe "Subscriber Properties" do
end end
end end
publish_message_inline(channel_1, headers, body + channel_1.to_s) EM.add_timer(0.5) do
publish_message_inline(channel_2, headers, body + channel_2.to_s) publish_message(channel_1, headers, body + channel_1.to_s)
publish_message_inline(channel_3, headers, body + channel_3.to_s) publish_message(channel_2, headers, body + channel_2.to_s)
publish_message_inline(channel_4, headers, body + channel_4.to_s) publish_message(channel_3, headers, body + channel_3.to_s)
publish_message_inline(channel_5, headers, body + channel_5.to_s) publish_message(channel_4, headers, body + channel_4.to_s)
publish_message_inline(channel_6, headers, body + channel_6.to_s) publish_message(channel_5, headers, body + channel_5.to_s)
publish_message(channel_6, headers, body + channel_6.to_s)
end
end end
end end
end end
...@@ -578,14 +580,13 @@ describe "Subscriber Properties" do ...@@ -578,14 +580,13 @@ describe "Subscriber Properties" do
nginx_run_server(config.merge(:max_subscribers_per_channel => 3, :subscriber_connection_ttl => "3s")) do |conf| nginx_run_server(config.merge(:max_subscribers_per_channel => 3, :subscriber_connection_ttl => "3s")) do |conf|
EventMachine.run do EventMachine.run do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get(:head => headers).stream do
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get(:head => headers).stream do
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get(:head => headers).stream do
sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub_4.callback do sub_4.callback do
sub_4.should be_http_status(403).without_body sub_4.should be_http_status(403).without_body
sub_4.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribers limit per channel has been exceeded.") sub_4.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'].should eql("Subscribers limit per channel has been exceeded.")
end
sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + other_channel.to_s).get :head => headers sub_5 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + other_channel.to_s).get :head => headers
sub_5.callback do sub_5.callback do
...@@ -595,6 +596,10 @@ describe "Subscriber Properties" do ...@@ -595,6 +596,10 @@ describe "Subscriber Properties" do
end end
end end
end end
end
end
end
end
it "should accept channels with '.b' in the name" do it "should accept channels with '.b' in the name" do
channel = 'room.b18.beautiful' channel = 'room.b18.beautiful'
...@@ -602,10 +607,10 @@ describe "Subscriber Properties" do ...@@ -602,10 +607,10 @@ describe "Subscriber Properties" do
nginx_run_server(config.merge(:ping_message_interval => nil, :header_template => nil, :footer_template => nil, :message_template => nil)) do |conf| nginx_run_server(config.merge(:ping_message_interval => nil, :header_template => nil, :footer_template => nil, :message_template => nil)) do |conf|
EventMachine.run do EventMachine.run do
publish_message_inline(channel, {'accept' => 'text/html'}, 'msg 1') publish_message(channel, {'accept' => 'text/html'}, 'msg 1')
publish_message_inline(channel, {'accept' => 'text/html'}, 'msg 2') publish_message(channel, {'accept' => 'text/html'}, 'msg 2')
publish_message_inline(channel, {'accept' => 'text/html'}, 'msg 3') publish_message(channel, {'accept' => 'text/html'}, 'msg 3')
publish_message_inline(channel, {'accept' => 'text/html'}, 'msg 4') publish_message(channel, {'accept' => 'text/html'}, 'msg 4')
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b3').get sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b3').get
sub.stream do |chunk| sub.stream do |chunk|
...@@ -904,15 +909,8 @@ describe "Subscriber Properties" do ...@@ -904,15 +909,8 @@ describe "Subscriber Properties" do
EventMachine.stop EventMachine.stop
end end
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body publish_message_inline(channel, {}, body)
pub_1.callback do publish_message_inline('test_' + channel, {}, body)
pub_1.should be_http_status(200)
end
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + 'test_' + channel.to_s).post :head => headers, :body => body
pub_2.callback do
pub_2.should be_http_status(200)
end
end end
end end
end end
...@@ -1024,7 +1022,7 @@ describe "Subscriber Properties" do ...@@ -1024,7 +1022,7 @@ describe "Subscriber Properties" do
sub_2.stream do |chunk| sub_2.stream do |chunk|
actual_response_2 += chunk actual_response_2 += chunk
end end
sub_2.callback do EM.add_timer(1.5) do
sub_1.should be_http_status(200) sub_1.should be_http_status(200)
sub_2.should be_http_status(200) sub_2.should be_http_status(200)
...@@ -1033,9 +1031,11 @@ describe "Subscriber Properties" do ...@@ -1033,9 +1031,11 @@ describe "Subscriber Properties" do
EventMachine.stop EventMachine.stop
end end
EM.add_timer(0.5) do
EventMachine::HttpRequest.new("http://#{nginx_host}:#{nginx_port.to_i}/pub/?id=" + channel.to_s).post :body => "#{body}_1" EventMachine::HttpRequest.new("http://#{nginx_host}:#{nginx_port.to_i}/pub/?id=" + channel.to_s).post :body => "#{body}_1"
EventMachine::HttpRequest.new("http://#{nginx_host}:#{nginx_port.to_i + 1}/pub/?id=" + channel.to_s).post :body => "#{body}_2" EventMachine::HttpRequest.new("http://#{nginx_host}:#{nginx_port.to_i + 1}/pub/?id=" + channel.to_s).post :body => "#{body}_2"
end end
end end
end end
end
end end
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
describe "Subscriber WebSocket" do describe "Subscriber WebSocket" do
let(:config) do let(:config) do
{ {
:workers => 1,
:header_template => nil, :header_template => nil,
:message_template => nil, :message_template => nil,
:footer_template => nil, :footer_template => nil,
...@@ -165,7 +166,7 @@ describe "Subscriber WebSocket" do ...@@ -165,7 +166,7 @@ describe "Subscriber WebSocket" do
nginx_run_server(config.merge(:header_template => "HEADER_TEMPLATE")) do |conf| nginx_run_server(config.merge(:header_template => "HEADER_TEMPLATE")) do |conf|
socket = open_socket(nginx_host, nginx_port) socket = open_socket(nginx_host, nginx_port)
socket.print("#{request}\r\n") socket.print("#{request}\r\n")
sleep(0.5) sleep(1)
headers, body = read_response_on_socket(socket, 'TEMPLATE') headers, body = read_response_on_socket(socket, 'TEMPLATE')
body.should eql("\201\017HEADER_TEMPLATE") body.should eql("\201\017HEADER_TEMPLATE")
socket.close socket.close
...@@ -226,7 +227,7 @@ describe "Subscriber WebSocket" do ...@@ -226,7 +227,7 @@ describe "Subscriber WebSocket" do
socket.print("#{request}\r\n") socket.print("#{request}\r\n")
headers, body = read_response_on_socket(socket) headers, body = read_response_on_socket(socket)
#wait for disconnect #wait for disconnect
sleep(1.5) sleep(1)
body, dummy = read_response_on_socket(socket, "\210\000") body, dummy = read_response_on_socket(socket, "\210\000")
body.should eql("\201\017FOOTER_TEMPLATE\210\000") body.should eql("\201\017FOOTER_TEMPLATE\210\000")
socket.close socket.close
...@@ -447,6 +448,8 @@ describe "Subscriber WebSocket" do ...@@ -447,6 +448,8 @@ describe "Subscriber WebSocket" do
headers, body = read_response_on_socket(socket) headers, body = read_response_on_socket(socket)
socket.print(frame) socket.print(frame)
sleep(1)
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30
pub.callback do pub.callback do
...@@ -475,6 +478,8 @@ describe "Subscriber WebSocket" do ...@@ -475,6 +478,8 @@ describe "Subscriber WebSocket" do
headers, body = read_response_on_socket(socket) headers, body = read_response_on_socket(socket)
socket.print(frame) socket.print(frame)
sleep(1)
EventMachine.run do EventMachine.run do
pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30 pub = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :timeout => 30
pub.callback do pub.callback do
...@@ -562,7 +567,7 @@ describe "Subscriber WebSocket" do ...@@ -562,7 +567,7 @@ describe "Subscriber WebSocket" do
socket.print("WRITE SOMETHING UNKNOWN\r\n") socket.print("WRITE SOMETHING UNKNOWN\r\n")
sleep 1 sleep(1)
error_log = File.read(conf.error_log) error_log = File.read(conf.error_log)
error_log.should_not include("client sent invalid") error_log.should_not include("client sent invalid")
...@@ -601,7 +606,7 @@ describe "Subscriber WebSocket" do ...@@ -601,7 +606,7 @@ describe "Subscriber WebSocket" do
socket.print("WRITE SOMETHING UNKNOWN\r\n") socket.print("WRITE SOMETHING UNKNOWN\r\n")
sleep 3 sleep(1)
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get
pub_2.callback do pub_2.callback do
......
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