Skip to content

Commit

Permalink
improving some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wandenberg committed Sep 14, 2011
1 parent cef7f30 commit 3ac5588
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 23 deletions.
4 changes: 3 additions & 1 deletion test/base_test_case.rb
Expand Up @@ -23,10 +23,12 @@ def setup
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
Expand Down Expand Up @@ -285,7 +287,7 @@ def add_test_timeout(timeout=5)
# 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
Expand Down
1 change: 1 addition & 0 deletions test/test_publisher_admin.rb
Expand Up @@ -473,6 +473,7 @@ def test_delete_channel_whith_subscriber_in_one_channel
EventMachine.stop
end
}
add_test_timeout
}
end

Expand Down
47 changes: 25 additions & 22 deletions test/test_send_signals.rb
Expand Up @@ -11,6 +11,7 @@ def config_test_send_hup_signal
@master_process = 'on'
@daemon = 'on'
@header_template = 'HEADER'
@disable_ignore_childs = true
end

def test_send_hup_signal
Expand Down Expand Up @@ -41,31 +42,31 @@ def test_send_hup_signal
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
Expand Down Expand Up @@ -102,6 +103,8 @@ def test_send_hup_signal
end
}
end

add_test_timeout(60)
}
end
end
67 changes: 67 additions & 0 deletions test/test_subscriber_connection_cleanup.rb
Expand Up @@ -30,6 +30,8 @@ def test_subscriber_connection_timeout
assert(response.include?(@footer_template), "Didn't received footer template")
EventMachine.stop
}

add_test_timeout(50)
}
end

Expand Down Expand Up @@ -59,6 +61,71 @@ def test_subscriber_connection_timeout_with_ping_message
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

0 comments on commit 3ac5588

Please sign in to comment.