Commit 3ac55889 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

improving some tests

parent cef7f302
......@@ -23,10 +23,12 @@ module BaseTestCase
end
def teardown
old_cld_trap = Signal.trap("CLD", "IGNORE") unless @disable_ignore_childs
unless @disable_start_stop_server
self.stop_server
end
self.delete_config_and_log_files
Signal.trap("CLD", old_cld_trap) unless @disable_ignore_childs
end
def nginx_executable
......@@ -285,7 +287,7 @@ http {
# activate subscriber mode for this location
push_stream_subscriber;
# activate eventsource support for this location
# activate event source support for this location
<%= "push_stream_subscriber_eventsource #{@subscriber_eventsource};" unless @subscriber_eventsource.nil? %>
# positional channel path
......
......@@ -473,6 +473,7 @@ class TestPublisherAdmin < Test::Unit::TestCase
EventMachine.stop
end
}
add_test_timeout
}
end
......
......@@ -11,6 +11,7 @@ class TestSendSignals < Test::Unit::TestCase
@master_process = 'on'
@daemon = 'on'
@header_template = 'HEADER'
@disable_ignore_childs = true
end
def test_send_hup_signal
......@@ -41,31 +42,31 @@ class TestSendSignals < Test::Unit::TestCase
pid = resp_1["by_worker"][0]['pid'].to_i
# send reload signal
POpen4::popen4("#{ nginx_executable } -c #{ config_filename } -s reload") do
# publish a message
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 30
pub_2.callback {
# add new subscriber
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers, :timeout => 30
sub_2.stream { |chunk|
response2 = response2 + chunk
if response2.strip == @header_template
# check statistics again
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers, :timeout => 30
pub_3.callback {
`#{ nginx_executable } -c #{ config_filename } -s reload`
resp_2 = JSON.parse(pub_3.response)
assert(resp_2.has_key?("channels"), "Didn't received the correct answer with channels info")
assert_equal(1, resp_2["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_2["published_messages"].to_i, "Didn't create messages")
assert_equal(2, resp_2["subscribers"].to_i, "Didn't create subscribers")
assert_equal(2, resp_2["by_worker"].count, "Didn't return infos by_worker")
# publish a message
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 30
pub_2.callback {
# add new subscriber
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers, :timeout => 30
sub_2.stream { |chunk|
response2 = response2 + chunk
if response2.strip == @header_template
# check statistics again
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers, :timeout => 30
pub_3.callback {
}
end
}
resp_2 = JSON.parse(pub_3.response)
assert(resp_2.has_key?("channels"), "Didn't received the correct answer with channels info")
assert_equal(1, resp_2["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_2["published_messages"].to_i, "Didn't create messages")
assert_equal(2, resp_2["subscribers"].to_i, "Didn't create subscribers")
assert_equal(2, resp_2["by_worker"].count, "Didn't return infos by_worker")
}
end
}
end
}
rescue JSON::ParserError
fail("Didn't receive a valid response")
EventMachine.stop
......@@ -102,6 +103,8 @@ class TestSendSignals < Test::Unit::TestCase
end
}
end
add_test_timeout(60)
}
end
end
......@@ -30,6 +30,8 @@ class TestSubscriberConnectionCleanup < Test::Unit::TestCase
assert(response.include?(@footer_template), "Didn't received footer template")
EventMachine.stop
}
add_test_timeout(50)
}
end
......@@ -59,6 +61,71 @@ class TestSubscriberConnectionCleanup < Test::Unit::TestCase
assert_equal(7, chunksReceived, "Received #{chunksReceived} chunks")
EventMachine.stop
}
add_test_timeout(50)
}
end
def config_test_multiple_subscribers_connection_timeout
@subscriber_connection_timeout = "5s"
@header_template = "HEADER_TEMPLATE"
@footer_template = "FOOTER_TEMPLATE"
@ping_message_interval = nil
end
def test_multiple_subscribers_connection_timeout
channel = 'ch_test_multiple_subscribers_connection_timeout'
headers = {'accept' => 'text/html'}
EventMachine.run {
response_1 = ''
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub_1.stream { |chunk|
response_1 += chunk
assert(response_1.include?(@header_template), "Didn't received header template")
}
sub_1.callback {
assert(response_1.include?(@footer_template), "Didn't received footer template")
}
sleep(2)
response_2 = ''
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub_2.stream { |chunk|
response_2 += chunk
assert(response_2.include?(@header_template), "Didn't received header template")
}
sub_2.callback {
assert(response_2.include?(@footer_template), "Didn't received footer template")
response_4 = ''
sub_4 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub_4.stream { |chunk|
response_4 += chunk
assert(response_4.include?(@header_template), "Didn't received header template")
}
sub_4.callback {
assert(response_4.include?(@footer_template), "Didn't received footer template")
EventMachine.stop
}
}
sleep(6)
response_3 = ''
sub_3 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub_3.stream { |chunk|
response_3 += chunk
assert(response_3.include?(@header_template), "Didn't received header template")
}
sub_3.callback {
assert(response_3.include?(@footer_template), "Didn't received footer template")
}
add_test_timeout(15)
}
end
end
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