Commit e32e1d01 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

speedup some tests

parent cf925122
......@@ -6,6 +6,7 @@ require 'ruby-debug'
require 'test/unit'
require 'em-http'
require 'json'
require 'socket'
module BaseTestCase
def setup
......@@ -181,6 +182,12 @@ module BaseTestCase
pub
end
def publish_message_in_socket(channel, body, socket)
post_channel_message = "POST /pub?id=#{channel} HTTP/1.0\r\nContent-Length: #{body.size}\r\n\r\n#{body}"
socket.print(post_channel_message)
read_response(socket)
end
def create_channel_by_subscribe(channel, headers, timeout=60, &block)
EventMachine.run {
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers, :timeout => timeout
......@@ -200,6 +207,21 @@ module BaseTestCase
end
end
def open_socket
TCPSocket.open(nginx_host, nginx_port)
end
def read_response(socket)
response = socket.readpartial(1)
while (tmp = socket.read_nonblock(256))
response += tmp
end
ensure
fail("Any response") if response.nil?
headers, body = response.split("\r\n\r\n", 2)
return headers, body
end
@@config_template = %q{
pid <%= @pid_file %>;
error_log <%= @main_error_log %> debug;
......
......@@ -349,6 +349,7 @@ class TestChannelStatistics < Test::Unit::TestCase
def config_test_get_detailed_channels_statistics_to_many_channels
@max_reserved_memory = '200m'
@keepalive = "on"
end
def test_get_detailed_channels_statistics_to_many_channels
......@@ -359,18 +360,13 @@ class TestChannelStatistics < Test::Unit::TestCase
#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 }
}
socket = open_socket
1.upto(10) do |j|
channel_name = "#{channel}#{i + j}"
headers, body = publish_message_in_socket(channel_name, body, socket)
fail("Don't create the channel") unless headers.include?("HTTP/1.1 200 OK")
end
socket.close
end
EventMachine.run {
......@@ -510,6 +506,7 @@ class TestChannelStatistics < Test::Unit::TestCase
def config_test_get_detailed_channels_statistics_to_many_channels_using_prefix
@max_reserved_memory = '200m'
@keepalive = "on"
end
def test_get_detailed_channels_statistics_to_many_channels_using_prefix
......@@ -520,18 +517,13 @@ class TestChannelStatistics < Test::Unit::TestCase
#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 }
}
socket = open_socket
1.upto(10) do |j|
channel_name = "#{channel}#{i + j}"
headers, body = publish_message_in_socket(channel_name, body, socket)
fail("Don't create the channel") unless headers.include?("HTTP/1.1 200 OK")
end
socket.close
end
EventMachine.run {
......
......@@ -5,6 +5,7 @@ class TestCreateManyChannels < Test::Unit::TestCase
def config_test_create_many_channels
@max_reserved_memory = "256m"
@keepalive = "on"
end
def test_create_many_channels
......@@ -14,18 +15,13 @@ class TestCreateManyChannels < Test::Unit::TestCase
channel = 'ch_test_create_many_channels_'
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 }
}
socket = open_socket
1.upto(10) do |j|
channel_name = "#{channel}#{i + j}"
headers, body = publish_message_in_socket(channel_name, body, socket)
fail("Don't create the channel") unless headers.include?("HTTP/1.1 200 OK")
end
socket.close
end
end
end
require File.expand_path('base_test_case', File.dirname(__FILE__))
require 'socket'
class TestKeepalive < Test::Unit::TestCase
include BaseTestCase
......@@ -38,15 +37,4 @@ class TestKeepalive < Test::Unit::TestCase
assert_equal("{\"channel\": \"#{channel}\", \"published_messages\": \"1\", \"stored_messages\": \"1\", \"subscribers\": \"0\"}\r\n", body, "Wrong response")
end
def read_response(socket)
response = socket.readpartial(1)
while (tmp = socket.read_nonblock(256))
response += tmp
end
ensure
fail("Any response") if response.nil?
headers, body = response.split("\r\n\r\n", 2)
return headers, body
end
end
......@@ -69,6 +69,7 @@ class TestPublishMessages < Test::Unit::TestCase
@message_template = "~text~"
@max_reserved_memory = "256m"
@ping_message_interval = nil
@keepalive = "on"
end
def test_publish_many_messages_in_the_same_channel
......@@ -84,22 +85,24 @@ class TestPublishMessages < Test::Unit::TestCase
response += chunk
recieved_messages = response.split("\r\n")
if recieved_messages.length >= 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
}
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 = 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 }
EM.add_timer(0.05) do
0.step(messagens_to_publish - 1, 10) do |i|
socket = open_socket
1.upto(10) do |j|
resp_headers, body = publish_message_in_socket(channel, body_prefix + (i+j).to_s, socket)
fail("Message was not published: " + body_prefix + (i+j).to_s) unless resp_headers.include?("HTTP/1.1 200 OK")
end
socket.close
end
end
add_test_timeout
}
end
......
......@@ -5,9 +5,9 @@ class TestSendSignals < Test::Unit::TestCase
def config_test_send_hup_signal
ENV['NGINX_WORKERS'] = '1'
@memory_cleanup_timeout = '2m'
@min_message_buffer_timeout = '2m'
@subscriber_connection_timeout = '2m'
@memory_cleanup_timeout = '40s'
@min_message_buffer_timeout = '60s'
@subscriber_connection_timeout = '65s'
@master_process = 'on'
@daemon = 'on'
@header_template = 'HEADER'
......
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