Commit aa417e95 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

refactoring and adding some tests

parent 4d97bae4
This diff is collapsed.
require 'test/unit'
require File.expand_path('test_broadcast_properties', File.dirname(__FILE__))
require File.expand_path('test_channel_statistics', File.dirname(__FILE__))
require File.expand_path('test_cleanup_memory', File.dirname(__FILE__))
require File.expand_path('test_comunication_properties', File.dirname(__FILE__))
require File.expand_path('test_create_many_channels', File.dirname(__FILE__))
require File.expand_path('test_publish_messages', File.dirname(__FILE__))
require File.expand_path('test_publisher_properties', File.dirname(__FILE__))
#require File.expand_path('test_setup_parameters', File.dirname(__FILE__))
require File.expand_path('test_publisher', File.dirname(__FILE__))
require File.expand_path('test_setup_parameters', File.dirname(__FILE__))
require File.expand_path('test_subscriber_connection_cleanup', File.dirname(__FILE__))
require File.expand_path('test_subscriber_properties', File.dirname(__FILE__))
require File.expand_path('test_subscriber', File.dirname(__FILE__))
......@@ -4,7 +4,6 @@ class TestBroadcastProperties < Test::Unit::TestCase
include BaseTestCase
def config_test_broadcast_channel_prefix
@test_config_file = "test_broadcast_channel_prefix.conf"
@authorized_channels_only = "on"
@header_template = "connected"
@broadcast_channel_prefix = "XXX_"
......@@ -38,7 +37,6 @@ class TestBroadcastProperties < Test::Unit::TestCase
end
def config_test_broadcast_channel_max_qtd
@test_config_file = "test_broadcast_channel_max_qtd.conf"
@authorized_channels_only = "on"
@header_template = "connected"
@broadcast_channel_prefix = "XXX_"
......
This diff is collapsed.
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestCreateManyChannels < Test::Unit::TestCase
include BaseTestCase
def config_test_message_cleanup
@min_message_buffer_timeout = '10s'
@max_reserved_memory = "32k"
@max_message_buffer_length = 100
@memory_cleanup_timeout = '30s'
end
def test_message_cleanup
channel = 'ch_test_message_cleanup'
headers = {'accept' => 'text/html'}
body = 'message to create a channel'
EventMachine.run {
# ensure space for a subscriber after memory was full
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
fail_if_connecttion_error(sub_1)
i = 0
EM.add_periodic_timer(0.05) do
i += 1
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 60
pub_1.callback {
if pub_1.response_header.status == 500
EventMachine.stop
end
}
fail_if_connecttion_error(pub_1)
end
}
EventMachine.run {
# ensure channel will not be cleaned up
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
fail_if_connecttion_error(sub_1)
stored_messages_setp_1 = 0
stored_messages_setp_2 = 0
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels_stats?id=' + channel.to_s).get :head => headers, :timeout => 60
pub_2.callback {
assert_equal(200, pub_2.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_2.response_header.content_length, "Don't received channels statistics")
stored_messages_setp_1 = JSON.parse(pub_2.response)["stored_messages"].to_i
sleep(40) #wait for message timeout and for cleanup timer
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels_stats?id=' + channel.to_s).get :head => headers, :timeout => 60
pub_3.callback {
assert_equal(200, pub_3.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_3.response_header.content_length, "Don't received channels statistics")
stored_messages_setp_2 = JSON.parse(pub_3.response)["stored_messages"].to_i
assert(stored_messages_setp_1 > stored_messages_setp_2, "Messages weren't clean up: #{stored_messages_setp_1} <= #{stored_messages_setp_2}")
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body, :timeout => 60
pub_4.callback {
assert_equal(200, pub_4.response_header.status, "Don't get channels statistics")
assert_equal(stored_messages_setp_2 + 1, JSON.parse(pub_4.response)["stored_messages"].to_i, "Don't get channels statistics")
EventMachine.stop
}
fail_if_connecttion_error(pub_4)
}
fail_if_connecttion_error(pub_3)
}
fail_if_connecttion_error(pub_2)
}
end
def config_test_channel_cleanup
@min_message_buffer_timeout = '10s'
@max_reserved_memory = "32k"
@memory_cleanup_timeout = '30s'
end
def test_channel_cleanup
channel = 'ch_test_channel_cleanup_'
headers = {'accept' => 'text/html'}
body = 'message to create a channel'
i = 0
EventMachine.run {
EM.add_periodic_timer(0.05) do
i += 1
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + i.to_s).post :head => headers, :body => body, :timeout => 60
pub_1.callback {
if pub_1.response_header.status == 500
EventMachine.stop
end
}
fail_if_connecttion_error(pub_1)
end
}
EventMachine.run {
channels_setp_1 = 0
channels_setp_2 = 0
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels_stats').get :head => headers, :timeout => 60
pub_2.callback {
assert_equal(200, pub_2.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_2.response_header.content_length, "Don't received channels statistics")
channels_setp_1 = JSON.parse(pub_2.response)["channels"].to_i
assert_equal(i, channels_setp_1, "Channels were not here anymore")
sleep(45) #wait for message timeout and for cleanup timer
pub_3 = EventMachine::HttpRequest.new(nginx_address + '/channels_stats').get :head => headers, :timeout => 60
pub_3.callback {
assert_equal(200, pub_3.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_3.response_header.content_length, "Don't received channels statistics")
channels_setp_2 = JSON.parse(pub_3.response)["channels"].to_i
assert(channels_setp_1 > channels_setp_2, "Channels weren't clean up: #{channels_setp_1} <= #{channels_setp_2}")
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s + (i + 1).to_s).post :head => headers, :body => body, :timeout => 60
pub_4.callback {
assert_equal(200, pub_4.response_header.status, "Don't get channels statistics")
pub_5 = EventMachine::HttpRequest.new(nginx_address + '/channels_stats').get :head => headers, :timeout => 60
pub_5.callback {
assert_equal(200, pub_5.response_header.status, "Don't get channels statistics")
assert_not_equal(0, pub_5.response_header.content_length, "Don't received channels statistics")
assert_equal(channels_setp_2 + 1, JSON.parse(pub_5.response)["channels"].to_i, "Don't get channels statistics")
EventMachine.stop
}
fail_if_connecttion_error(pub_5)
}
fail_if_connecttion_error(pub_4)
}
fail_if_connecttion_error(pub_3)
}
fail_if_connecttion_error(pub_2)
}
end
end
require 'rubygems'
require 'em-http'
require 'test/unit'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestComunicationProperties < Test::Unit::TestCase
include BaseTestCase
def config_test_all_authorized
@test_config_file = "test_all_authorized.conf"
@authorized_channels_only = "off"
@header_template = "connected"
end
def test_all_authorized
channel = 'ch1'
channel = 'ch_test_all_authorized'
headers = {'accept' => 'text/html'}
EventMachine.run {
......@@ -27,13 +23,12 @@ class TestComunicationProperties < Test::Unit::TestCase
end
def config_test_only_authorized
@test_config_file = "test_only_authorized.conf"
@authorized_channels_only = "on"
@header_template = "connected"
end
def test_only_authorized
channel = 'ch2'
channel = 'ch_test_only_authorized'
headers = {'accept' => 'text/html'}
body = 'message to create a channel'
......@@ -41,6 +36,8 @@ class TestComunicationProperties < Test::Unit::TestCase
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub_1.callback { |chunk|
assert_equal(403, sub_1.response_header.status, "Subscriber was not forbidden")
assert_equal(0, sub_1.response_header.content_length, "Should response only with headers")
assert_equal("Subscriber could not create channels.", sub_1.response_header['X_NGINX_PUSHSTREAM_EXPLAIN'], "Didn't receive the right error message")
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
pub.callback {
......@@ -58,7 +55,6 @@ class TestComunicationProperties < Test::Unit::TestCase
end
def config_test_message_buffer_timeout
@test_config_file = "test_message_buffer_timeout.conf"
@authorized_channels_only = "off"
@header_template = "connected"
@message_template = "~text~"
......@@ -66,7 +62,7 @@ class TestComunicationProperties < Test::Unit::TestCase
end
def test_message_buffer_timeout
channel = 'ch3'
channel = 'ch_test_message_buffer_timeout'
headers = {'accept' => 'text/html'}
body = 'message to test buffer timeout '
response_1 = response_2 = response_3 = ""
......@@ -112,7 +108,6 @@ class TestComunicationProperties < Test::Unit::TestCase
end
def config_test_message_template
@test_config_file = "test_message_template.conf"
@authorized_channels_only = "off"
@header_template = "header"
@message_template = '{\"duplicated\":\"~channel~\", \"channel\":\"~channel~\", \"message\":\"~text~\", \"message_id\":\"~id~\"}'
......@@ -120,25 +115,25 @@ class TestComunicationProperties < Test::Unit::TestCase
end
def test_message_template
channel = 'ch4'
channel = 'ch_test_message_template'
headers = {'accept' => 'text/html'}
body = 'message to create a channel'
publish_message(channel, headers, body)
response = ""
EventMachine.run {
chunksReceived = 0
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers, :timeout => 60
sub.stream { |chunk|
chunksReceived += 1
if chunksReceived == 1
assert_equal("#{@header_template}\r\n", chunk, "Didn't received header template")
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
fail_if_connecttion_error(pub)
end
if chunksReceived == 2
assert_equal("{\"duplicated\":\"ch4\", \"channel\":\"#{channel}\", \"message\":\"#{body}\", \"message_id\":\"1\"}\r\n", chunk, "Didn't received message formatted: #{chunk}")
end
if chunksReceived == 3
assert_equal("{\"duplicated\":\"\", \"channel\":\"\", \"message\":\"\", \"message_id\":\"-1\"}\r\n", chunk, "Didn't received ping message: #{chunk}")
response += chunk
lines = response.split("\r\n")
if lines.length >= 3
assert_equal("#{@header_template}", lines[0], "Didn't received header template")
assert_equal("{\"duplicated\":\"#{channel}\", \"channel\":\"#{channel}\", \"message\":\"#{body}\", \"message_id\":\"1\"}", lines[1], "Didn't received message formatted: #{lines[1]}")
assert_equal("{\"duplicated\":\"\", \"channel\":\"\", \"message\":\"\", \"message_id\":\"-1\"}", lines[2], "Didn't received ping message: #{lines[2]}")
EventMachine.stop
end
}
......
require 'rubygems'
require 'popen4'
require 'em-http'
require 'test/unit'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestCreateManyChannels < Test::Unit::TestCase
include BaseTestCase
def initialize(opts)
super(opts)
@test_config_file = "test_create_many_channels.conf"
def config_test_create_many_channels
@max_reserved_memory = "256m"
end
......@@ -24,8 +18,11 @@ class TestCreateManyChannels < Test::Unit::TestCase
EM.add_periodic_timer(0.05) do
i += 1
if i <= channels_to_be_created
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=ch' + i.to_s ).post :head => headers, :body => body, :timeout => 30
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
channels_callback += 1
}
fail_if_connecttion_error(pub)
......
require 'rubygems'
require 'popen4'
require 'em-http'
require 'test/unit'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestPublishMessages < Test::Unit::TestCase
include BaseTestCase
def initialize(opts)
super(opts)
@test_config_file = "test_publish_messages.conf"
@header_template = ""
def config_test_publish_messages
@header_template = nil
@message_template = "~text~"
end
def test_publish_messages
headers = {'accept' => 'text/html'}
body = 'published unique message'
channel = 'ch1'
channel = 'ch_test_publish_messages'
EventMachine.run {
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
......@@ -32,29 +26,30 @@ class TestPublishMessages < Test::Unit::TestCase
}
end
def config_test_publish_many_messages_in_the_same_channel
@header_template = nil
@message_template = "~text~"
@max_reserved_memory = "256m"
end
def test_publish_many_messages_in_the_same_channel
headers = {'accept' => 'text/html'}
body_prefix = 'published message '
channel = 'ch2'
channel = 'ch_test_publish_many_messages_in_the_same_channel'
messagens_to_publish = 400
recieved_messages = 0
response = ""
EventMachine.run {
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
sub.stream { | chunk |
chunk.each {|s|
if s.chomp and s.chomp != ""
recieved_messages +=1
end
}
response += chunk
recieved_messages = response.split("\r\n").length
if chunk.include?(body_prefix + messagens_to_publish.to_s + "\r\n")
if recieved_messages >= messagens_to_publish
EventMachine.stop
end
}
sub.callback {
assert_equal(messagens_to_publish, recieved_messages, "The published messages was not received correctly")
}
fail_if_connecttion_error(sub)
i = 0
......@@ -62,6 +57,11 @@ class TestPublishMessages < Test::Unit::TestCase
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)
end
end
......
This diff is collapsed.
require 'rubygems'
require 'popen4'
require 'em-http'
require 'test/unit'
require 'json'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestPublisherProperties < Test::Unit::TestCase
include BaseTestCase
def initialize(opts)
super(opts)
@header_template = ""
@message_template = "~text~"
end
def config_test_stored_messages
@test_config_file = "test_store_messages.conf"
@store_messages = "on"
end
def test_stored_messages
headers = {'accept' => 'application/json'}
body = 'published message'
channel = 'ch1'
EventMachine.run {
pub_1 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
pub_1.callback {
response = JSON.parse(pub_1.response)
assert_equal(1, response["stored_messages"].to_i, "Not stored messages")
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
pub_2.callback {
response = JSON.parse(pub_2.response)
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
def config_test_not_stored_messages
@test_config_file = "test_not_store_messages.conf"
@store_messages = "off"
end
def test_not_stored_messages
headers = {'accept' => 'application/json'}
body = 'published message'
channel = 'ch2'
EventMachine.run {
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
pub.callback {
response = JSON.parse(pub.response)
assert_equal(0, response["stored_messages"].to_i, "Stored messages")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
def config_test_max_stored_messages
@test_config_file = "test_max_stored_messages.conf"
@store_messages = "on"
@max_message_buffer_length = 4
end
def test_max_stored_messages
headers = {'accept' => 'application/json'}
body_prefix = 'published message '
channel = 'ch3'
messagens_to_publish = 10
EventMachine.run {
i = 0
EM.add_periodic_timer(0.05) 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 {
response = JSON.parse(pub.response)
assert(response["stored_messages"].to_i <= @max_message_buffer_length, "Stored more messages then configured")
}
fail_if_connecttion_error(pub)
else
EventMachine.stop
end
end
}
end
def config_test_max_channel_id_length
@test_config_file = "test_max_channel_id_length.conf"
@max_channel_id_length = 5
end
def test_max_channel_id_length
headers = {'accept' => 'application/json'}
body = 'published message'
channel = '123456'
EventMachine.run {
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s ).post :head => headers, :body => body, :timeout => 30
pub.callback {
response = JSON.parse(pub.response)
assert_equal("12345", response["channel"], "No crop the channel id")
EventMachine.stop
}
fail_if_connecttion_error(pub)
}
end
end
......@@ -3,9 +3,13 @@ require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestSetuParameters < Test::Unit::TestCase
include BaseTestCase
def initialize(opts)
super(opts)
@disable_start_stop_server = true
end
def test_ping_message_interval_cannot_be_zero
expected_error_message = "push_stream_ping_message_interval cannot be zero"
@test_config_file = "test_ping_message_interval_cannot_be_zero.conf"
@ping_message_interval = 0
self.create_config_file
......@@ -15,8 +19,8 @@ class TestSetuParameters < Test::Unit::TestCase
def test_ping_message_interval_cannot_be_set_without_a_message_template
expected_error_message = "cannot have ping message if push_stream_message_template is not set or blank"
@test_config_file = "test_ping_message_interval_cannot_be_set_without_a_message_template.conf"
@ping_message_interval = "1s"
@message_template = nil
self.create_config_file
stderr_msg = self.start_server
......@@ -25,7 +29,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_ping_message_interval_cannot_be_set_if_message_template_is_blank
expected_error_message = "cannot have ping message if push_stream_message_template is not set or blank"
@test_config_file = "test_ping_message_interval_cannot_be_set_if_message_template_is_blank.conf"
@ping_message_interval = "1s"
@message_template = ""
......@@ -36,7 +39,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_subscriber_disconnect_interval_cannot_be_zero
expected_error_message = "push_stream_subscriber_disconnect_interval cannot be zero"
@test_config_file = "test_subscriber_disconnect_interval_cannot_be_zero.conf"
@subscriber_disconnect_interval = 0
self.create_config_file
......@@ -46,7 +48,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_subscriber_connection_timeout_cannot_be_zero
expected_error_message = "push_stream_subscriber_connection_timeout cannot be zero"
@test_config_file = "test_subscriber_connection_timeout_cannot_be_zero.conf"
@subscriber_connection_timeout = 0
self.create_config_file
......@@ -56,7 +57,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_subscriber_disconnect_interval_cannot_be_set_without_a_connection_timeout
expected_error_message = "cannot set subscriber disconnect interval if push_stream_subscriber_connection_timeout is not set or zero"
@test_config_file = "test_subscriber_disconnect_interval_cannot_be_set_without_a_connection_timeout.conf"
@subscriber_disconnect_interval = "1s"
self.create_config_file
......@@ -66,7 +66,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_subscriber_connection_timeout_cannot_be_set_without_a_disconnect_interval
expected_error_message = "cannot set subscriber connection timeout if push_stream_subscriber_disconnect_interval is not set or zero"
@test_config_file = "test_subscriber_connection_timeout_cannot_be_set_without_a_disconnect_interval.conf"
@subscriber_connection_timeout = "1s"
self.create_config_file
......@@ -76,7 +75,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_max_channel_id_length_cannot_be_zero
expected_error_message = "push_stream_max_channel_id_length cannot be zero"
@test_config_file = "test_max_channel_id_length_cannot_be_zero.conf"
@max_channel_id_length = 0
self.create_config_file
......@@ -86,7 +84,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_min_message_buffer_timeout_cannot_be_zero
expected_error_message = "push_stream_min_message_buffer_timeout cannot be zero"
@test_config_file = "test_min_message_buffer_timeout_cannot_be_zero.conf"
@min_message_buffer_timeout = 0
self.create_config_file
......@@ -96,7 +93,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_max_message_buffer_length_cannot_be_zero
expected_error_message = "push_stream_max_message_buffer_length cannot be zero"
@test_config_file = "test_max_message_buffer_length_cannot_be_zero.conf"
@max_message_buffer_length = 0
self.create_config_file
......@@ -106,8 +102,9 @@ class TestSetuParameters < Test::Unit::TestCase
def test_store_messages_cannot_be_set_without_set_max_message_buffer_length_or_min_message_buffer_timeout
expected_error_message = "push_stream_store_messages cannot be set without set max message buffer length or min message buffer timeout"
@test_config_file = "test_store_messages_cannot_be_set_without_set_max_message_buffer_length_or_min_message_buffer_timeout.conf"
@store_messages = 'on'
@min_message_buffer_timeout = nil
@max_message_buffer_length = nil
self.create_config_file
stderr_msg = self.start_server
......@@ -116,7 +113,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_broadcast_channel_max_qtd_cannot_be_zero
expected_error_message = "push_stream_broadcast_channel_max_qtd cannot be zero"
@test_config_file = "test_broadcast_channel_max_qtd_cannot_be_zero.conf"
@broadcast_channel_max_qtd = 0
self.create_config_file
......@@ -126,7 +122,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_broadcast_channel_max_qtd_cannot_be_set_without_broadcast_channel_prefix
expected_error_message = "cannot set broadcast channel max qtd if push_stream_broadcast_channel_prefix is not set or blank"
@test_config_file = "test_broadcast_channel_max_qtd_cannot_be_set_without_broadcast_channel_prefix.conf"
@broadcast_channel_max_qtd = 1
self.create_config_file
......@@ -136,7 +131,6 @@ class TestSetuParameters < Test::Unit::TestCase
def test_broadcast_channel_max_qtd_cannot_be_set_without_broadcast_channel_prefix
expected_error_message = "cannot set broadcast channel max qtd if push_stream_broadcast_channel_prefix is not set or blank"
@test_config_file = "test_broadcast_channel_max_qtd_cannot_be_set_without_broadcast_channel_prefix.conf"
@broadcast_channel_max_qtd = 1
@broadcast_channel_prefix = ""
......@@ -147,7 +141,36 @@ class TestSetuParameters < Test::Unit::TestCase
def test_broadcast_channel_prefix_cannot_be_set_without_broadcast_channel_max_qtd
expected_error_message = "cannot set broadcast channel prefix if push_stream_broadcast_channel_max_qtd is not set"
@test_config_file = "test_broadcast_channel_prefix_cannot_be_set_without_broadcast_channel_max_qtd.conf"
@broadcast_channel_prefix = "broad_"
@broadcast_channel_max_qtd = nil
self.create_config_file
stderr_msg = self.start_server
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
def test_max_number_of_channels_cannot_be_zero
expected_error_message = "push_stream_max_number_of_channels cannot be zero"
@max_number_of_channels = 0
self.create_config_file
stderr_msg = self.start_server
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
def test_max_number_of_broadcast_channels_cannot_be_zero
expected_error_message = "push_stream_max_number_of_broadcast_channels cannot be zero"
@max_number_of_broadcast_channels = 0
self.create_config_file
stderr_msg = self.start_server
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
def test_max_number_of_broadcast_channels_cannot_be_smaller_than_broadcast_channel_max_qtd
expected_error_message = "max number of broadcast channels cannot be smaller than value in push_stream_broadcast_channel_max_qtd"
@max_number_of_broadcast_channels = 3
@broadcast_channel_max_qtd = 4
@broadcast_channel_prefix = "broad_"
self.create_config_file
......@@ -155,4 +178,12 @@ class TestSetuParameters < Test::Unit::TestCase
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
def test_memory_cleanup_timeout
expected_error_message = "memory cleanup timeout cannot't be less than 30."
@memory_cleanup_timeout = '15s'
self.create_config_file
stderr_msg = self.start_server
assert(stderr_msg.include?(expected_error_message), "Message error not founded: '#{ expected_error_message }' recieved '#{ stderr_msg }'")
end
end
This diff is collapsed.
require 'rubygems'
require 'em-http'
require 'test/unit'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestSubscriberConnectionCleanup < Test::Unit::TestCase
include BaseTestCase
def config_test_subscriber_connection_timeout
@test_config_file = "test_subscriber_connection_timeout.conf"
@subscriber_connection_timeout = "37s"
@subscriber_disconnect_interval = "1s"
@header_template = "HEADER_TEMPLATE"
@ping_message_interval = "0s"
@ping_message_interval = nil
end
def test_subscriber_connection_timeout
channel = 'ch1'
channel = 'ch_test_subscriber_connection_timeout'
headers = {'accept' => 'text/html'}
start = Time.now
......@@ -36,28 +32,27 @@ class TestSubscriberConnectionCleanup < Test::Unit::TestCase
end
def config_test_subscriber_disconnect_interval
@test_config_file = "test_subscriber_disconnect_interval.conf"
@subscriber_connection_timeout = "37s"
@ping_message_interval = "5s"
@subscriber_disconnect_interval = "5s"
@subscriber_disconnect_interval = "2s"
end
def test_subscriber_disconnect_interval
channel = 'ch2'
channel = 'ch_test_subscriber_disconnect_interval'
headers = {'accept' => 'text/html'}
start = Time.now
chuncksReceived = 0
chunksReceived = 0
EventMachine.run {
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub.stream { |chunk|
chuncksReceived += 1;
chunksReceived += 1;
}
sub.callback {
stop = Time.now
elapsed = time_diff_sec(start, stop)
assert(elapsed >= 40 && elapsed <= 40.5, "Disconnect was in #{elapsed} seconds")
assert_equal(9, chuncksReceived, "Received #{chuncksReceived} chuncks")
assert(elapsed >= 38 && elapsed <= 39.5, "Disconnect was in #{elapsed} seconds")
assert_equal(8, chunksReceived, "Received #{chunksReceived} chunks")
EventMachine.stop
}
fail_if_connecttion_error(sub)
......
require 'rubygems'
require 'em-http'
require 'test/unit'
require File.expand_path('base_test_case', File.dirname(__FILE__))
class TestSubscriberProperties < Test::Unit::TestCase
include BaseTestCase
def config_test_header_template
@test_config_file = "test_header_template.conf"
@header_template = "HEADER\r\nTEMPLATE\r\n1234\r\n"
@authorized_channels_only = "off"
@subscriber_disconnect_interval = nil
end
def test_header_template
channel = 'ch1'
channel = 'ch_test_header_template'
headers = {'accept' => 'text/html'}
EventMachine.run {
......@@ -27,13 +24,12 @@ class TestSubscriberProperties < Test::Unit::TestCase
end
def config_test_content_type
@test_config_file = "test_content_type.conf"
@content_type = "custom content type"
@authorized_channels_only = "off"
end
def test_content_type
channel = 'ch2'
channel = 'ch_test_content_type'
headers = {'accept' => 'text/html'}
EventMachine.run {
......@@ -47,32 +43,31 @@ class TestSubscriberProperties < Test::Unit::TestCase
end
def config_test_ping_message_interval
@test_config_file = "test_ping_message_interval.conf"
@subscriber_connection_timeout = "0s"
@subscriber_connection_timeout = nil
@ping_message_interval = "2s"
end
def test_ping_message_interval
channel = 'ch3'
channel = 'ch_test_ping_message_interval'
headers = {'accept' => 'text/html'}
step1 = step2 = step3 = step4 = nil
chuncksReceived = 0
chunksReceived = 0
EventMachine.run {
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => 60
sub.stream { |chunk|
chuncksReceived += 1;
step1 = Time.now if chuncksReceived == 1
step2 = Time.now if chuncksReceived == 2
step3 = Time.now if chuncksReceived == 3
step4 = Time.now if chuncksReceived == 4
if chuncksReceived == 4
chunksReceived += 1;
step1 = Time.now if chunksReceived == 1
step2 = Time.now if chunksReceived == 2
step3 = Time.now if chunksReceived == 3
step4 = Time.now if chunksReceived == 4
if chunksReceived == 4
EventMachine.stop
end
}
sub.callback {
assert_equal(4, chuncksReceived, "Didn't received expected messages")
assert_equal(4, chunksReceived, "Didn't received expected messages")
interval1 = time_diff_sec(step2, step1).round
interval2 = time_diff_sec(step4, step3).round
assert_equal(interval1, interval2, "Wrong #{interval1}, #{interval2} intervals")
......
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