From bfe213a1c3918befd4a26b1d64a61a21486d81ba Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 1 Nov 2013 22:01:45 +0000 Subject: tests: further speed up output buffering test Increase scans of log files and use shorter sleep intervals to get faster notification of successful timeout. --- test/test_output_buffering.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb index 4ddfe7b..a448062 100644 --- a/test/test_output_buffering.rb +++ b/test/test_output_buffering.rb @@ -41,7 +41,7 @@ class TestOutputBuffering < Testcase output_buffer(true, :http09) end - def output_buffer(btype, check_type, delay = 4) + def output_buffer(btype, check_type) err = @err cfg = Yahns::Config.new host, port = @srv.addr[3], @srv.addr[1] @@ -62,7 +62,8 @@ class TestOutputBuffering < Testcase case check_type when :curl - # curl is faster for piping gigantic wads of data than Net::HTTP + # curl is faster for piping gigantic wads of data than Net::HTTP, + # and we need to be able to throttle a bit to force output buffering c = IO.popen("curl -N -sSf http://#{host}:#{port}/") wait_for_full(c) dig, nr = md5sum(c) @@ -232,6 +233,7 @@ class TestOutputBuffering < Testcase cfg = Yahns::Config.new size = RAND.size * NR host, port = @srv.addr[3], @srv.addr[1] + re = /timeout on :wait_writable after 0\.1s$/ cfg.instance_eval do ru = lambda do |e| if e["PATH_INFO"] == "/bh" @@ -245,19 +247,25 @@ class TestOutputBuffering < Testcase app(:rack, ru) do listen "#{host}:#{port}" output_buffering false - client_timeout 3 + client_timeout 0.1 logger(Logger.new(apperr.path)) end end logger(Logger.new(err.path)) end pid = mkserver(cfg) + + wait_for_timeout_msg = lambda do + Timeout.timeout(6) do + sleep(0.01) until File.readlines(apperr.path).grep(re).size == 2 + end + end threads = [] threads << Thread.new do c = get_tcp_client(host, port) c.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") wait_for_full(c) - sleep(3.5) # wait for timeout + wait_for_timeout_msg.call assert_operator c.nread, :>, 0 c end @@ -266,7 +274,7 @@ class TestOutputBuffering < Testcase c = get_tcp_client(host, port) c.write("GET /bh HTTP/1.1\r\nHost: example.com\r\n\r\n") wait_for_full(c) - sleep(3.5) # wait for timeout + wait_for_timeout_msg.call assert_operator c.nread, :>, 0 c end @@ -274,7 +282,7 @@ class TestOutputBuffering < Testcase assert_operator size, :>, threads[0].value.read.size assert_operator size, :>, threads[1].value.read.size msg = File.readlines(apperr.path) - msg = msg.grep(/timeout on :wait_writable after 3s$/) + msg = msg.grep(re) assert_equal 2, msg.size threads.each { |t| t.value.close } ensure @@ -305,9 +313,7 @@ class TestOutputBuffering < Testcase pid = mkserver(cfg) c = get_tcp_client(host, port) c.write "GET / HTTP/1.0\r\n\r\n" - begin - sleep 1 - end while c.nread == 0 + wait_for_full(c) nr = 0 last = nil c.each_line do |line| -- cgit v1.2.3-24-ge0c7