diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-02-15 09:27:13 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-02-16 12:44:33 +0000 |
commit | fcb41385271818586a162d02aeb23bc3414a602e (patch) | |
tree | 901bf1609b9024812344ad794d5092477318274b | |
parent | 476cc380a94db3355f818b2c798cdeeb0c626cc0 (diff) | |
download | cmogstored-fcb41385271818586a162d02aeb23bc3414a602e.tar.gz |
This is a tricky test and doesn't always succeed, since it's hard to tell how many file descriptors glibc will use internally.
-rw-r--r-- | test/http_idle_expire.rb | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/test/http_idle_expire.rb b/test/http_idle_expire.rb index 17610ea..8d8dc0f 100644 --- a/test/http_idle_expire.rb +++ b/test/http_idle_expire.rb @@ -4,6 +4,7 @@ # License: GPLv3 or later (see COPYING for details) require 'test/test_helper' require 'io/wait' +require 'io/nonblock' class TestHTTPIdleExpire < Test::Unit::TestCase def setup @@ -37,7 +38,7 @@ class TestHTTPIdleExpire < Test::Unit::TestCase @pid = fork { Process.setrlimit(Process::RLIMIT_NOFILE, nofile) - # $stderr.reopen(@err) + $stderr.reopen(@err) @err.close exec(*cmd) } @@ -47,20 +48,39 @@ class TestHTTPIdleExpire < Test::Unit::TestCase def test_idle_expire return if @kq - clients = [ get_client(300, @http_port) ] - clients[0].write 'G' - 3.times do |i| - c = get_client(1, @http_port) - assert_kind_of TCPSocket, c - clients << c + # keep connecting until we don't get a response + clients = [] + loop do + c = get_client(300, @http_port) + c.nonblock = true + c.write "GET / HTTP/1.1\r\nHost: #@host:#@http_port\r\n\r\n" + if c.wait(1) + clients << c + else # not accepted + c.close + break + end + end + + # drain the sockets + clients.each do |c| + while line = c.gets + break if line == "\r\n" + end + c.write("G") # start the next request end + + # wait for timeouts to be valid sleep(@idle_timeout + 1) - new_clients = [] - 4.times do |i| + + # start new clients to trigger keepalive expiry + new_clients = clients.map do c = get_client(1, @http_port) + c.nonblock = true assert_kind_of TCPSocket, c - new_clients << c + c end + clients.each do |c| assert_equal [[c],[],[]], IO.select([c], nil, nil, 1) assert_nil c.gets, "expect nil (EOF)" @@ -68,6 +88,7 @@ class TestHTTPIdleExpire < Test::Unit::TestCase end new_clients.each do |c| c.write("GET / HTTP/1.0\r\n\r\n") + assert c.wait(5) buf = c.read assert_match(%r{\AHTTP/1\.1 }, buf) assert_match(%r{\r\n\r\n\z}, buf) |