diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-10-18 17:28:20 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-18 17:28:20 +0000 |
commit | ee6b1150abc9ee0c429ac88b839214e7933c4f92 (patch) | |
tree | 38446f49e472f34e6646bc5456af4149fc7ba08d | |
parent | fe6358be43e54d91c2beb9b52ced0437ad45f913 (diff) | |
download | yahns-ee6b1150abc9ee0c429ac88b839214e7933c4f92.tar.gz |
Unfortunately, this will need further work because tests are MT and FD counts vary, so reproducing reliable FD counts will need to rely on exec + FD_CLOEXEC.
-rw-r--r-- | test/test_client_expire.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb index 8bc82fa..525c2e8 100644 --- a/test/test_client_expire.rb +++ b/test/test_client_expire.rb @@ -79,4 +79,52 @@ class TestClientExpire < Testcase ensure quit_wait(pid) end + + def test_client_expire_desperate + skip "disabled since FD counts vary heavily in an MT process" + err = @err + cfg = Yahns::Config.new + host, port = @srv.addr[3], @srv.addr[1] + cfg.instance_eval do + GTL.synchronize do + h = { "Content-Length" => "0" } + app(:rack, lambda { |e| [ 200, h, [] ]}) do + listen "#{host}:#{port}", sndbuf: 2048, rcvbuf: 2048 + client_timeout 1 + end + client_expire_threshold 1.0 + end + logger(Logger.new(err.path)) + end + srv = Yahns::Server.new(cfg) + pid = fork do + Process.setrlimit :NOFILE, 512, 1024 + ENV["YAHNS_FD"] = @srv.fileno.to_s + srv.start.join + end + f = TCPSocket.new(host, port) + s = TCPSocket.new(host, port) + req = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" + s.write(req) + str = Timeout.timeout(20) { s.readpartial(666) } + assert_match(%r{keep-alive}, str) + sleep 3 + system "ab -c 1000 -n 10000 -k http://#{host}:#{port}/ 2>&1" + + [ f, s ].each do |io| + assert_raises(Errno::EPIPE,Errno::ECONNRESET) do + req.each_byte { |b| io.write(b.chr) } + end + io.close + end + errs = File.readlines(err.path).grep(/ERROR/) + File.truncate(err.path, 0) # avoid error on teardown + re = %r{consider raising open file limits} # - accept, consider raising open file limits} + assert_equal errs.grep(re), errs + rescue => e + Yahns::Log.exception(Logger.new($stderr), "test", e) + raise + ensure + quit_wait(pid) + end end |