Commit 6f2d144c authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

cleanning some tests

parent 25771076
......@@ -18,7 +18,6 @@ module BaseTestCase
self.create_config_file
unless @disable_start_stop_server
self.stop_server
self.start_server
end
end
......@@ -127,13 +126,6 @@ module BaseTestCase
(finish - start)
end
def fail_if_connecttion_error(client)
client.errback { |error|
fail("Erro inexperado na execucao do teste: #{error.last_effective_url.nil? ? "" : error.last_effective_url.request_uri} #{error.response}")
EventMachine.stop
}
end
def default_configuration
@master_process = 'off'
@daemon = 'off'
......@@ -158,16 +150,23 @@ module BaseTestCase
def publish_message(channel, headers, body)
EventMachine.run {
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 30
pub_1.callback {
assert_equal(200, pub_1.response_header.status, "Request was not accepted")
assert_not_equal(0, pub_1.response_header.content_length, "Empty response was received")
response = JSON.parse(pub_1.response)
pub = publish_message_inline(channel, headers, body) do
assert_not_equal(0, pub.response_header.content_length, "Empty response was received")
response = JSON.parse(pub.response)
assert_equal(channel, response["channel"].to_s, "Channel was not recognized")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
end
}
end
def publish_message_inline(channel, headers, body, &block)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 30
pub.callback {
fail("Request was not accepted") if pub.response_header.status != 200
block.call unless block.nil?
}
pub.errback { |error| fail("Erro inexperado na execucao do teste: #{error.last_effective_url.nil? ? "" : error.last_effective_url.request_uri} #{error.response}") }
pub
end
def create_channel_by_subscribe(channel, headers, timeout=60, &block)
......@@ -179,7 +178,6 @@ module BaseTestCase
sub_1.callback {
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......
......@@ -28,11 +28,8 @@ class TestBroadcastProperties < Test::Unit::TestCase
assert_equal("#{@header_template}\r\n", chunk, "Didn't received header template")
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
}
fail_if_connecttion_error(sub_1)
}
fail_if_connecttion_error(pub)
}
end
......@@ -61,11 +58,8 @@ class TestBroadcastProperties < Test::Unit::TestCase
sub_2.stream { |chunk|
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
}
fail_if_connecttion_error(sub_1)
}
fail_if_connecttion_error(pub)
}
end
end
......@@ -14,7 +14,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(0, pub_1.response_header.content_length, "Recieved a non empty response")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -38,7 +37,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(0, response["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -59,7 +57,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(1, response["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
end
end
......@@ -75,7 +72,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(0, response["infos"].length, "Received info whithout_created_channels")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -100,7 +96,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(0, response["infos"][0]["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -132,7 +127,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(0, response["infos"][0]["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -154,7 +148,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(1, response["infos"][0]["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
end
end
......@@ -175,7 +168,6 @@ class TestChannelStatistics < Test::Unit::TestCase
end
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -203,7 +195,6 @@ class TestChannelStatistics < Test::Unit::TestCase
end
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -237,7 +228,6 @@ class TestChannelStatistics < Test::Unit::TestCase
end
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -258,7 +248,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(1, response["subscribers"].to_i, "Wrong number for subscribers")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
end
end
......@@ -292,7 +281,6 @@ class TestChannelStatistics < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -356,7 +344,6 @@ class TestChannelStatistics < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -370,8 +357,21 @@ class TestChannelStatistics < Test::Unit::TestCase
body = 'body'
number_of_channels = 20000
#create channel
number_of_channels.times { |i| publish_message("#{channel}#{i}", headers, body) }
#create channels
0.step(number_of_channels - 1, 10) do |i|
EventMachine.run {
publish_message_inline("#{channel}#{i + 1}", headers, body)
publish_message_inline("#{channel}#{i + 2}", headers, body)
publish_message_inline("#{channel}#{i + 3}", headers, body)
publish_message_inline("#{channel}#{i + 4}", headers, body)
publish_message_inline("#{channel}#{i + 5}", headers, body)
publish_message_inline("#{channel}#{i + 6}", headers, body)
publish_message_inline("#{channel}#{i + 7}", headers, body)
publish_message_inline("#{channel}#{i + 8}", headers, body)
publish_message_inline("#{channel}#{i + 9}", headers, body)
publish_message_inline("#{channel}#{i + 10}", headers, body) { EventMachine.stop }
}
end
EventMachine.run {
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=ALL').get :head => headers, :timeout => 30
......@@ -382,7 +382,6 @@ class TestChannelStatistics < Test::Unit::TestCase
assert_equal(number_of_channels, response["infos"].length, "Didn't received info about the created channels")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......
......@@ -18,7 +18,6 @@ class TestComunicationProperties < Test::Unit::TestCase
assert_equal("#{@header_template}\r\n", chunk, "Didn't received header template")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
......@@ -46,11 +45,8 @@ class TestComunicationProperties < Test::Unit::TestCase
assert_equal("#{@header_template}\r\n", chunk, "Didn't received header template")
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
}
fail_if_connecttion_error(pub)
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -70,14 +66,12 @@ class TestComunicationProperties < Test::Unit::TestCase
EventMachine.run {
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
fail_if_connecttion_error(pub)
EM.add_timer(2) do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers, :timeout => 60
sub_1.stream { |chunk|
response_1 += chunk
sub_1.close_connection if response_1.include?(body)
}
fail_if_connecttion_error(sub_1)
end
EM.add_timer(6) do
......@@ -86,7 +80,6 @@ class TestComunicationProperties < Test::Unit::TestCase
response_2 += chunk
sub_2.close_connection if response_2.include?(body)
}
fail_if_connecttion_error(sub_2)
end
#message will be certainly expired at 15 seconds, (min_message_buffer_timeout / 3) + 1
......@@ -96,7 +89,6 @@ class TestComunicationProperties < Test::Unit::TestCase
response_3 += chunk
sub_3.close_connection if response_3.include?(body)
}
fail_if_connecttion_error(sub_3)
end
EM.add_timer(17) do
......@@ -138,7 +130,6 @@ class TestComunicationProperties < Test::Unit::TestCase
EventMachine.stop
end
}
fail_if_connecttion_error(sub)
}
end
......@@ -172,7 +163,6 @@ class TestComunicationProperties < Test::Unit::TestCase
EventMachine.stop
end
}
fail_if_connecttion_error(sub)
}
end
end
......@@ -11,22 +11,21 @@ class TestCreateManyChannels < Test::Unit::TestCase
headers = {'accept' => 'application/json'}
body = 'channel started'
channels_to_be_created = 4000
channel = 'ch_test_create_many_channels_'
EventMachine.run {
i = 0
EM.add_periodic_timer(0.001) do
i += 1
if i <= channels_to_be_created
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=ch_test_create_many_channels_' + i.to_s ).post :head => headers, :body => body, :timeout => 30
pub.callback {
if pub.response_header.status != 200
assert_equal(200, pub.response_header.status, "Channel was not created: ch_test_create_many_channels_" + i.to_s)
end
}
else
EventMachine.stop
end
end
}
0.step(channels_to_be_created - 1, 10) do |i|
EventMachine.run {
publish_message_inline("#{channel}#{i + 1}", headers, body)
publish_message_inline("#{channel}#{i + 2}", headers, body)
publish_message_inline("#{channel}#{i + 3}", headers, body)
publish_message_inline("#{channel}#{i + 4}", headers, body)
publish_message_inline("#{channel}#{i + 5}", headers, body)
publish_message_inline("#{channel}#{i + 6}", headers, body)
publish_message_inline("#{channel}#{i + 7}", headers, body)
publish_message_inline("#{channel}#{i + 8}", headers, body)
publish_message_inline("#{channel}#{i + 9}", headers, body)
publish_message_inline("#{channel}#{i + 10}", headers, body) { EventMachine.stop }
}
end
end
end
......@@ -19,10 +19,8 @@ class TestPublishMessages < Test::Unit::TestCase
assert_equal(body + "\r\n", chunk, "The published message was not received correctly")
EventMachine.stop
}
fail_if_connecttion_error(sub)
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
fail_if_connecttion_error(pub)
}
end
......@@ -38,32 +36,28 @@ class TestPublishMessages < Test::Unit::TestCase
body_prefix = 'published message '
channel = 'ch_test_publish_many_messages_in_the_same_channel'
messagens_to_publish = 1500
recieved_messages = 0
response = ""
EventMachine.run {
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub.stream { | chunk |
response += chunk
recieved_messages = response.split("\r\n").length
recieved_messages = response.split("\r\n")
if recieved_messages >= messagens_to_publish
if recieved_messages.length >= messagens_to_publish
assert_equal(body_prefix + messagens_to_publish.to_s, recieved_messages.last, "Didn't receive all messages")
EventMachine.stop
end
}
fail_if_connecttion_error(sub)
req = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s )
i = 0
EM.add_periodic_timer(0.001) do
i += 1
if i <= messagens_to_publish
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body_prefix + i.to_s, :timeout => 30
pub.callback {
if pub.response_header.status != 200
assert_equal(200, pub.response_header.status, "Massage was not published: " + body_prefix + i.to_s)
end
}
fail_if_connecttion_error(pub)
pub = req.post :head => headers, :body => body_prefix + i.to_s, :timeout => 30
pub.callback { fail("Massage was not published: " + body_prefix + i.to_s) if pub.response_header.status != 200 }
end
end
}
......
......@@ -14,7 +14,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("No channel id provided.", pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
......@@ -31,7 +30,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(0, pub_1.response_header.content_length, "Recieved a non empty response")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
EventMachine.run {
......@@ -43,7 +41,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(channel_2, response["channel"].to_s, "Channel was not recognized")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -62,7 +59,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(channel, response["channel"].to_s, "Channel was not recognized")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
EventMachine.run {
......@@ -74,7 +70,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(channel, response["channel"].to_s, "Channel was not recognized")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
end
......@@ -111,7 +106,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -128,7 +122,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Channel id not authorized for this method.", pub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -153,7 +146,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(413, pub_1.response_header.status, "Request was accepted")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -178,7 +170,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(200, pub_1.response_header.status, "Request was not accepted")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -203,7 +194,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(200, pub_1.response_header.status, "Request was not accepted")
EventMachine.stop
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -228,9 +218,7 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(2, response["stored_messages"].to_i, "Not stored messages")
EventMachine.stop
}
fail_if_connecttion_error(pub_2)
}
fail_if_connecttion_error(pub_1)
}
end
......@@ -250,7 +238,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(0, response["stored_messages"].to_i, "Stored messages")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
......@@ -277,7 +264,6 @@ class TestPublisher < Test::Unit::TestCase
response = JSON.parse(pub.response)
stored_messages = response["stored_messages"].to_i
}
fail_if_connecttion_error(pub)
else
EventMachine.stop
assert(stored_messages == @max_message_buffer_length, "Stored more messages then configured")
......@@ -303,7 +289,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Channel id is too large.", pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
......@@ -323,7 +308,6 @@ class TestPublisher < Test::Unit::TestCase
assert_not_equal(0, pub.response_header.content_length, "Should response channel info")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
EventMachine.run {
......@@ -334,7 +318,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Number of channels were exceeded.", pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
......@@ -356,7 +339,6 @@ class TestPublisher < Test::Unit::TestCase
assert_not_equal(0, pub.response_header.content_length, "Should response channel info")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
EventMachine.run {
......@@ -367,7 +349,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Number of channels were exceeded.", pub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
......
......@@ -74,23 +74,32 @@ class TestSendSignals < Test::Unit::TestCase
end
}
# wait some time to first worker die
EM.add_timer(45) do
i = 0
# check if first worker die
EM.add_periodic_timer(1) do
# check statistics again
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers, :timeout => 30
pub_4.callback {
resp_3 = JSON.parse(pub_4.response)
assert(resp_3.has_key?("channels"), "Didn't received the correct answer with channels info")
assert_equal(1, resp_3["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_3["published_messages"].to_i, "Didn't create messages")
assert_equal(1, resp_3["subscribers"].to_i, "Didn't create subscribers")
assert_equal(1, resp_3["by_worker"].count, "Didn't return infos by_worker")
pid2 = resp_3["by_worker"][0]['pid'].to_i
assert(resp_3.has_key?("by_worker"), "Didn't received the correct answer with channels info")
assert_not_equal(pid, pid2, "Didn't recreate worker")
if resp_3["by_worker"].count == 1
assert_equal(1, resp_3["channels"].to_i, "Didn't create channel")
assert_equal(1, resp_3["published_messages"].to_i, "Didn't create messages")
assert_equal(1, resp_3["subscribers"].to_i, "Didn't create subscribers")
assert_equal(1, resp_3["by_worker"].count, "Didn't return infos by_worker")
pid2 = resp_3["by_worker"][0]['pid'].to_i
EventMachine.stop
assert_not_equal(pid, pid2, "Didn't recreate worker")
EventMachine.stop
end
i = i + 1
if i == 60
fail("Worker didn't die in 60 seconds")
EventMachine.stop
end
}
end
}
......
......@@ -41,7 +41,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -56,7 +55,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("No channel id provided.", sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
......@@ -84,7 +82,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -104,7 +101,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Channel id is too large.", sub.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
......@@ -120,7 +116,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Channel id not authorized for this method.", sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -161,7 +156,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -202,7 +196,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
}
fail_if_connecttion_error(multi)
}
end
......@@ -222,7 +215,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Subscriber could not create channels.", sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -245,7 +237,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(200, sub_1.response_header.status, "Channel was founded")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -272,7 +263,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(200, sub_1.response_header.status, "Channel was founded")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -299,7 +289,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Subscriber could not create channels.", sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -329,7 +318,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Subscriber could not create channels.", sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -390,7 +378,6 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
end
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -451,25 +438,13 @@ class TestPublisher < Test::Unit::TestCase
EventMachine.stop
end
}
fail_if_connecttion_error(sub_1)
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_1.to_s ).post :head => headers, :body => body + channel_1.to_s, :timeout => 30
fail_if_connecttion_error(pub_1)
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_2.to_s ).post :head => headers, :body => body + channel_2.to_s, :timeout => 30
fail_if_connecttion_error(pub_2)
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_3.to_s ).post :head => headers, :body => body + channel_3.to_s, :timeout => 30
fail_if_connecttion_error(pub_3)
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_4.to_s ).post :head => headers, :body => body + channel_4.to_s, :timeout => 30
fail_if_connecttion_error(pub_4)
pub_5 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_5.to_s ).post :head => headers, :body => body + channel_5.to_s, :timeout => 30
fail_if_connecttion_error(pub_5)
pub_6 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel_6.to_s ).post :head => headers, :body => body + channel_6.to_s, :timeout => 30
fail_if_connecttion_error(pub_6)
publish_message_inline(channel_1, headers, body + channel_1.to_s)
publish_message_inline(channel_2, headers, body + channel_2.to_s)
publish_message_inline(channel_3, headers, body + channel_3.to_s)
publish_message_inline(channel_4, headers, body + channel_4.to_s)
publish_message_inline(channel_5, headers, body + channel_5.to_s)
publish_message_inline(channel_6, headers, body + channel_6.to_s)
}
end
......@@ -495,9 +470,7 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Number of channels were exceeded.", sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -525,9 +498,7 @@ class TestPublisher < Test::Unit::TestCase
assert_equal("Number of channels were exceeded.", sub_2.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
}
fail_if_connecttion_error(sub_1)
}
end
......@@ -563,7 +534,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(body, response['text'], "Wrong message")
EventMachine.stop
}
fail_if_connecttion_error(sub_1)
sub_2 = EventMachine::HttpRequest.new(nginx_address + '/sub2/' + channel.to_s + '.b1').get :head => headers, :timeout => 30
sub_2.stream { |chunk|
......@@ -573,11 +543,9 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(body, response['msg'], "Wrong message")
EventMachine.stop
}
fail_if_connecttion_error(sub_2)
#publish a message
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
fail_if_connecttion_error(pub_1)
publish_message_inline(channel, headers, body)
}
EventMachine.run {
......@@ -589,7 +557,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(body, response['text'], "Wrong message")
EventMachine.stop
}
fail_if_connecttion_error(sub_3)
}
EventMachine.run {
......@@ -601,7 +568,6 @@ class TestPublisher < Test::Unit::TestCase
assert_equal(body, response['msg'], "Wrong message")
EventMachine.stop
}
fail_if_connecttion_error(sub_4)
}
end
......
......@@ -26,13 +26,13 @@ class TestSubscriberConnectionCleanup < Test::Unit::TestCase
assert(elapsed >= 38 && elapsed <= 39.5, "Disconnect was in #{elapsed} seconds")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
def config_test_subscriber_connection_timeout_with_ping_message
@subscriber_connection_timeout = "37s"
@ping_message_interval = "5s"
@header_template = nil
end
def test_subscriber_connection_timeout_with_ping_message
......@@ -50,10 +50,9 @@ class TestSubscriberConnectionCleanup < Test::Unit::TestCase
stop = Time.now
elapsed = time_diff_sec(start, stop)
assert(elapsed >= 38 && elapsed <= 39.5, "Disconnect was in #{elapsed} seconds")
assert_equal(8, chunksReceived, "Received #{chunksReceived} chunks")
assert_equal(7, chunksReceived, "Received #{chunksReceived} chunks")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
end
......@@ -18,7 +18,6 @@ class TestSubscriberProperties < Test::Unit::TestCase
assert_equal("#{@header_template}\r\n", chunk, "Didn't received header template")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
......@@ -37,7 +36,6 @@ class TestSubscriberProperties < Test::Unit::TestCase
assert_equal(@content_type, sub.response_header['CONTENT_TYPE'], "Didn't received correct content type")
EventMachine.stop
}
fail_if_connecttion_error(sub)
}
end
......@@ -61,9 +59,7 @@ class TestSubscriberProperties < Test::Unit::TestCase
step2 = Time.now if chunksReceived == 2
step3 = Time.now if chunksReceived == 3
step4 = Time.now if chunksReceived == 4
if chunksReceived == 4
EventMachine.stop
end
EventMachine.stop if chunksReceived == 4
}
sub.callback {
assert_equal(4, chunksReceived, "Didn't received expected messages")
......@@ -71,7 +67,6 @@ class TestSubscriberProperties < Test::Unit::TestCase
interval2 = time_diff_sec(step4, step3).round
assert_equal(interval1, interval2, "Wrong #{interval1}, #{interval2} intervals")
}
fail_if_connecttion_error(sub)
}
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