From 3008ae6ea9e33abeb9c7628d9b8a72256f55e725 Mon Sep 17 00:00:00 2001 From: raggi Date: Thu, 4 Feb 2010 00:55:12 +0000 Subject: [PATCH] Tighten timeouts and so on for faster tests, 90s - 25s --- tests/test_attach.rb | 2 +- tests/test_basic.rb | 11 ++++++++++- tests/test_file_watch.rb | 2 +- tests/test_httpclient.rb | 21 +++++++++++++++------ tests/test_ltp.rb | 18 +++++++++++++----- tests/test_next_tick.rb | 2 +- tests/test_pending_connect_timeout.rb | 4 ++-- tests/test_process_watch.rb | 2 +- tests/test_pure.rb | 11 ++++++++++- tests/test_sasl.rb | 2 +- tests/test_send_file.rb | 23 ++++++++++++++++------- tests/test_servers.rb | 2 +- tests/test_timers.rb | 4 ++-- 13 files changed, 74 insertions(+), 30 deletions(-) diff --git a/tests/test_attach.rb b/tests/test_attach.rb index aa577f684..2359a9605 100644 --- a/tests/test_attach.rb +++ b/tests/test_attach.rb @@ -46,7 +46,7 @@ def notify_readable def unbind EM.next_tick do $sock.write("def\n") - EM.add_timer(0.5){ EM.stop } + EM.add_timer(0.1){ EM.stop } end end end diff --git a/tests/test_basic.rb b/tests/test_basic.rb index d2b0cff47..fdec991b2 100644 --- a/tests/test_basic.rb +++ b/tests/test_basic.rb @@ -152,6 +152,15 @@ def post_init end end + def setup_timeout(timeout = 4) + EM.schedule { + start_time = EM.current_time + EM.add_periodic_timer(0.01) { + raise "timeout" if EM.current_time - start_time >= timeout + } + } + end + # From ticket #50 def test_byte_range_send $received = '' @@ -160,7 +169,7 @@ def test_byte_range_send EM::start_server TestHost, TestPort, BrsTestSrv EM::connect TestHost, TestPort, BrsTestCli - EM::add_timer(0.5) { assert(false, 'test timed out'); EM.stop; Kernel.warn "test timed out!" } + setup_timeout } assert_equal($sent, $received) end diff --git a/tests/test_file_watch.rb b/tests/test_file_watch.rb index 3ba1a4dab..73a28a66b 100644 --- a/tests/test_file_watch.rb +++ b/tests/test_file_watch.rb @@ -38,7 +38,7 @@ def test_events File.open(file.path, 'w'){ |f| f.puts 'hi' } # delete it - EM.add_timer(0.25){ file.close; file.delete } + EM.add_timer(0.01){ file.close; file.delete } } assert_equal($path, $tmp_path) diff --git a/tests/test_httpclient.rb b/tests/test_httpclient.rb index 09c8c7ab2..11d4f98d1 100644 --- a/tests/test_httpclient.rb +++ b/tests/test_httpclient.rb @@ -44,7 +44,7 @@ def teardown def test_http_client ok = false EventMachine.run { - c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80 + c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80 c.callback { ok = true EventMachine.stop @@ -59,7 +59,7 @@ def test_http_client def test_http_client_1 ok = false EventMachine.run { - c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80 + c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80 c.callback {ok = true; EventMachine.stop} c.errback {EventMachine.stop} } @@ -71,7 +71,7 @@ def test_http_client_1 def test_http_client_2 ok = false EventMachine.run { - c = EventMachine::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80 + c = EventMachine::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80 c.callback {|result| ok = true; EventMachine.stop @@ -154,6 +154,15 @@ def send_response close_connection_after_writing end end + + def setup_timeout(timeout = 4) + EM.schedule { + start_time = EM.current_time + EM.add_periodic_timer(0.01) { + raise "timeout" if EM.current_time - start_time >= timeout + } + } + end # TODO, this is WRONG. The handler is asserting an HTTP 1.1 request, but the client # is sending a 1.0 request. Gotta fix the client @@ -161,7 +170,7 @@ def test_post response = nil EventMachine.run { EventMachine.start_server Localhost, Localport, PostContent - EventMachine.add_timer(2) {raise "timed out"} + setup_timeout(2) c = EventMachine::Protocols::HttpClient.request( :host=>Localhost, :port=>Localport, @@ -186,7 +195,7 @@ def test_post def test_cookie ok = false EM.run { - c = EM::Protocols::HttpClient.send :request, :host => "www.bayshorenetworks.com", :port => 80, :cookie=>"aaa=bbb" + c = EM::Protocols::HttpClient.send :request, :host => "www.google.com", :port => 80, :cookie=>"aaa=bbb" c.callback {|result| ok = true; EventMachine.stop @@ -202,7 +211,7 @@ def test_version_1_0 ok = false EM.run { c = EM::P::HttpClient.request( - :host => "www.bayshorenetworks.com", + :host => "www.google.com", :port => 80, :version => "1.0" ) diff --git a/tests/test_ltp.rb b/tests/test_ltp.rb index ff7b97898..3bf5a87d3 100644 --- a/tests/test_ltp.rb +++ b/tests/test_ltp.rb @@ -55,7 +55,15 @@ def unbind EM.add_timer(0.1) { EM.stop } end end - + + def setup_timeout(timeout = 4) + EM.schedule { + start_time = EM.current_time + EM.add_periodic_timer(0.01) { + raise "timeout" if EM.current_time - start_time >= timeout + } + } + end def test_simple_lines lines_received = [] @@ -63,7 +71,7 @@ def test_simple_lines EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn| conn.instance_eval "@line_buffer = lines_received" end - EventMachine.add_timer(4) {assert(false, "test timed out")} + setup_timeout EventMachine.connect TestHost, TestPort, StopClient do |c| c.send_data "aaa\nbbb\r\nccc\n" @@ -87,7 +95,7 @@ def test_overlength_lines EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn| conn.instance_eval "@error_message = lines_received" end - EventMachine.add_timer(4) {assert(false, "test timed out")} + setup_timeout EventMachine.connect TestHost, TestPort, StopClient do |c| c.send_data "a" * (16*1024 + 1) @@ -126,7 +134,7 @@ def test_lines_and_text EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn| conn.instance_eval "@lines = lines_received; @text = text_received" end - EventMachine.add_timer(4) {assert(false, "test timed out")} + setup_timeout EventMachine.connect TestHost, TestPort, StopClient do |c| c.set_receive_data { |data| output << data } @@ -166,7 +174,7 @@ def test_binary_text EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn| conn.instance_eval "@lines = lines_received; @text = text_received" end - EventMachine.add_timer(4) {assert(false, "test timed out")} + setup_timeout EventMachine.connect TestHost, TestPort, StopClient do |c| c.set_receive_data { |data| output << data } diff --git a/tests/test_next_tick.rb b/tests/test_next_tick.rb index 42667e9d1..ad329992e 100644 --- a/tests/test_next_tick.rb +++ b/tests/test_next_tick.rb @@ -61,7 +61,7 @@ def test_run_run def test_pre_run_queue x = false EM.next_tick { EM.stop; x = true } - EM.run { EM.add_timer(0.2) { EM.stop } } + EM.run { EM.add_timer(0.01) { EM.stop } } assert x end diff --git a/tests/test_pending_connect_timeout.rb b/tests/test_pending_connect_timeout.rb index 9cafed979..453ba9afa 100644 --- a/tests/test_pending_connect_timeout.rb +++ b/tests/test_pending_connect_timeout.rb @@ -39,10 +39,10 @@ def test_for_real EM.heartbeat_interval = 0.1 $start = Time.now c = EM.connect("1.2.3.4", 54321, TimeoutHandler) - c.pending_connect_timeout = 5 + c.pending_connect_timeout = 0.2 } - assert_in_delta(5, (Time.now - $start), 0.3) + assert_in_delta(0.2, (Time.now - $start), 0.1) end end diff --git a/tests/test_process_watch.rb b/tests/test_process_watch.rb index 54e734962..140f7edac 100644 --- a/tests/test_process_watch.rb +++ b/tests/test_process_watch.rb @@ -35,7 +35,7 @@ def test_events child = EM.watch_process($fork_pid, ChildProcessWatcher) $pid = child.pid - EM.add_timer(0.5){ + EM.add_timer(0.2){ Process.kill('TERM', $fork_pid) } } diff --git a/tests/test_pure.rb b/tests/test_pure.rb index 3d747b03d..d47c036ba 100644 --- a/tests/test_pure.rb +++ b/tests/test_pure.rb @@ -108,10 +108,19 @@ def test_connaccepted EM.run { EM.start_server "0.0.0.0", 60002 EM.connect "0.0.0.0", 60002, TestConnaccepted - EM::Timer.new(1) {timeout = true; EM.stop} + setup_timeout(1) } assert_equal( false, timeout ) end + + def setup_timeout(timeout = 4) + EM.schedule { + start_time = EM.current_time + EM.add_periodic_timer(0.01) { + raise "timeout" if EM.current_time - start_time >= timeout + } + } + end def test_reactor_running a = false diff --git a/tests/test_sasl.rb b/tests/test_sasl.rb index 3fcb2c1ed..e38946635 100644 --- a/tests/test_sasl.rb +++ b/tests/test_sasl.rb @@ -56,7 +56,7 @@ def test_sasl c = EM.connect( Host, Port, SaslClient ) d = c.validate?( TestUser, TestPsw ) - d.timeout 2 + d.timeout 1 d.callback { resp = true EM.stop diff --git a/tests/test_send_file.rb b/tests/test_send_file.rb index e71da0652..dc7883ed6 100644 --- a/tests/test_send_file.rb +++ b/tests/test_send_file.rb @@ -63,6 +63,15 @@ def teardown File.unlink( TestFilename ) if File.exist?( TestFilename ) end + def setup_timeout(timeout = 4) + EM.schedule { + start_time = EM.current_time + EM.add_periodic_timer(0.01) { + raise "timeout" if EM.current_time - start_time >= timeout + } + } + end + def test_send_file File.open( TestFilename, "w" ) {|f| f << ("A" * 5000) @@ -72,7 +81,7 @@ def test_send_file EM.run { EM.start_server TestHost, TestPort, TestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } @@ -95,7 +104,7 @@ def test_send_large_file assert_raises( ex_class ) { EM.run { EM.start_server TestHost, TestPort, TestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end @@ -131,7 +140,7 @@ def test_stream_file_data EM.run { EM.start_server TestHost, TestPort, StreamTestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end @@ -151,7 +160,7 @@ def test_stream_chunked_file_data EM.run { EM.start_server TestHost, TestPort, ChunkStreamTestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end @@ -175,7 +184,7 @@ def test_stream_bad_file data = '' EM.run { EM.start_server TestHost, TestPort, BadFileTestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end @@ -198,7 +207,7 @@ def test_stream_large_file_data EM.run { EM.start_server TestHost, TestPort, StreamTestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end @@ -223,7 +232,7 @@ def test_stream_large_chunked_file_data EM.run { EM.start_server TestHost, TestPort, ChunkStreamTestModule - EM.add_timer(2) {EM.stop} # avoid hanging in case of error + setup_timeout EM.connect TestHost, TestPort, TestClient do |c| c.data_to { |d| data << d } end diff --git a/tests/test_servers.rb b/tests/test_servers.rb index f0b38508f..aab41210f 100644 --- a/tests/test_servers.rb +++ b/tests/test_servers.rb @@ -61,7 +61,7 @@ def run_test_stop_server assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).size >= 1, "Server didn't start") EM.stop_server sig # Give the server some time to shutdown. - EM.add_timer(0.1) { + EM.add_timer(0.2) { assert(grep_netstat(LocalTcpRexp).grep(%r(#{Port})).empty?, "Servers didn't stop") EM.stop } diff --git a/tests/test_timers.rb b/tests/test_timers.rb index 0db99e9a0..c4c53f39c 100644 --- a/tests/test_timers.rb +++ b/tests/test_timers.rb @@ -98,9 +98,9 @@ def test_periodic_timer_cancel def test_add_periodic_timer_cancel x = 0 EventMachine.run { - pt = EM.add_periodic_timer(0.25) { x += 1 } + pt = EM.add_periodic_timer(0.1) { x += 1 } EM.cancel_timer(pt) - EM.add_timer(0.5) { EM.stop } + EM.add_timer(0.2) { EM.stop } } assert( x == 0 ) end