Commit cbfa6b69 authored by Wandenberg's avatar Wandenberg

make cleanup test more stable and faster using a socket to publish messages

parent c5abed57
......@@ -30,10 +30,8 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status, content|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status, content|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -53,10 +51,7 @@ describe "Cleanup Memory" do
# connect a subscriber on new worker
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status2, content2|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status2, content2|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -65,10 +60,7 @@ describe "Cleanup Memory" do
fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status3, content3|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_4.callback do
pub_4.should be_http_status(200).with_body
......@@ -79,21 +71,15 @@ describe "Cleanup Memory" do
EventMachine.stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it "should discard old messages", :cleanup => true do
......@@ -137,8 +123,8 @@ describe "Cleanup Memory" do
end
end
it "should cleanup message memory without max messages stored per channelXXX", :cleanup => true do
channel = 'ch_test_message_cleanup_without_max_messages_stored_per_chann'
it "should cleanup message memory without max messages stored per channel", :cleanup => true do
channel = 'ch_test_message_cleanup_without_max_messages_stored_per_channel'
body = 'message to create a channel'
expected_time_for_clear = 25
......@@ -151,10 +137,7 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status, content|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status, content|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -170,10 +153,7 @@ describe "Cleanup Memory" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status2, content2|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status2, content2|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do
......@@ -182,10 +162,7 @@ describe "Cleanup Memory" do
fail("Don't publish more messages") if published_messages_setp_1 == published_messages_setp_2
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status3, content3|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_4.callback do
pub_4.should be_http_status(200).with_body
......@@ -195,25 +172,19 @@ describe "Cleanup Memory" do
EventMachine.stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it "should cleanup memory used for create channels", :cleanup => true do
channel = 'ch_test_channel_cleanup_'
channel = 'ch_test_channel_cleanup_%d'
body = 'message to create a channel'
nginx_run_server(config.merge(:message_ttl => '2s'), :timeout => test_timeout) do |conf|
......@@ -223,11 +194,7 @@ describe "Cleanup Memory" do
expected_time_for_clear = 45
EventMachine.run do
i = 0
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + i.to_s, headers, body, {
:error => Proc.new do |status, content|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status, content|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -237,11 +204,7 @@ describe "Cleanup Memory" do
execute_changes_on_environment(conf) do
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true, :check_channels => true}) do
j = 0
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + j.to_s, headers, body, {
:error => Proc.new do |status2, content2|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status2, content2|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -249,11 +212,7 @@ describe "Cleanup Memory" do
fail("Don't create more channel") if published_messages_setp_1 == JSON.parse(pub_2.response)["published_messages"].to_i
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true, :check_channels => true}) do
i = 0
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + i.to_s, headers, body, {
:error => Proc.new do |status3, content3|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_4.callback do
pub_4.should be_http_status(200).with_body
......@@ -263,22 +222,13 @@ describe "Cleanup Memory" do
EventMachine.stop
end
end
})
i += 1
end
end
end
end
})
j += 1
end
end
end
end
end
})
i += 1
end
end
end
end
......@@ -296,10 +246,7 @@ describe "Cleanup Memory" do
# ensure channel will not be cleaned up
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status, content|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status, content|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do
......@@ -312,10 +259,8 @@ describe "Cleanup Memory" do
sub_1 = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s).get :head => headers
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status2, content2|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status2, content2|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_2.callback do
......@@ -324,10 +269,8 @@ describe "Cleanup Memory" do
published_messages_setp_2.should_not eql(published_messages_setp_1)
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel, headers, body, {
:error => Proc.new do |status3, content3|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats?id=' + channel.to_s).get :head => headers
pub_4.callback do
pub_4.should be_http_status(200).with_body
......@@ -336,25 +279,19 @@ describe "Cleanup Memory" do
EventMachine.stop
end
end
})
end
end
end
end
})
end
end
end
end
end
})
end
end
end
end
it "should cleanup memory used for publish messages with store 'off' and without subscriber", :cleanup => true do
channel = 'ch_test_message_cleanup_with_store_off_without_subscriber'
channel = 'ch_test_message_cleanup_with_store_off_without_subscriber %d'
body = 'message to create a channel'
expected_time_for_clear = 45
......@@ -363,11 +300,8 @@ describe "Cleanup Memory" do
published_messages_setp_2 = 0
EventMachine.run do
i = 0
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + i.to_s, headers, body, {
:error => Proc.new do |status, content|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status, content|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -377,11 +311,7 @@ describe "Cleanup Memory" do
execute_changes_on_environment(conf) do
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true, :check_channels => true}) do
j = 0
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + j.to_s, headers, body, {
:error => Proc.new do |status2, content2|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status2, content2|
start = Time.now
pub_2 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_2.callback do
......@@ -390,10 +320,7 @@ describe "Cleanup Memory" do
fail("Don't create more channel") if published_messages_setp_1 == published_messages_setp_2
wait_until_trash_is_empty(start, expected_time_for_clear, {:check_stored_messages => true, :check_channels => true}) do
fill_memory_timer = EventMachine::PeriodicTimer.new(0.001) do
publish_message_inline_with_callbacks(channel + i.to_s, headers, body, {
:error => Proc.new do |status3, content3|
fill_memory_timer.cancel
publish_messages_until_fill_the_memory(channel, body) do |status3, content3|
pub_4 = EventMachine::HttpRequest.new(nginx_address + '/channels-stats').get :head => headers
pub_4.callback do
pub_4.should be_http_status(200).with_body
......@@ -402,23 +329,14 @@ describe "Cleanup Memory" do
EventMachine.stop
end
end
})
i += 1
end
end
end
end
})
j += 1
end
end
end
end
end
})
i += 1
end
end
end
end
......@@ -569,7 +487,8 @@ describe "Cleanup Memory" do
:daemon => 'on',
:shared_memory_size => "129k",
:message_ttl => '10s',
:max_messages_stored_per_channel => nil
:max_messages_stored_per_channel => nil,
:keepalive_requests => 200
}
end
......
......@@ -61,14 +61,18 @@ def create_channel_by_subscribe(channel, headers, timeout=60, &block)
end
end
def publish_message_inline_with_callbacks(channel, headers, body, callbacks = {})
pub = EventMachine::HttpRequest.new(nginx_address + '/pub?id=' + channel.to_s).post :head => headers, :body => body
pub.callback do
if pub.response_header.status == 200
callbacks[:success].call(pub.response_header.status, pub.response) unless callbacks[:success].nil?
else
callbacks[:error].call(pub.response_header.status, pub.response) unless callbacks[:error].nil?
end
def publish_messages_until_fill_the_memory(channel, body, &block)
i = 0
resp_headers, resp_body = nil
socket = open_socket(nginx_host, nginx_port)
while (true) do
socket.print("POST /pub?id=#{channel.to_s % (i)} HTTP/1.1\r\nHost: localhost\r\nContent-Length: #{body.size}\r\n\r\n#{body}")
resp_headers, resp_body = read_response_on_socket(socket, {:wait_for => "}\r\n"})
break unless resp_headers.match(/200 OK/)
i += 1
end
pub
socket.close
status = resp_headers.match(/HTTP[^ ]* ([^ ]*)/)[1]
block.call(status, resp_body) unless block.nil?
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