From 3741b945dcaf2e432f9e0088b4553d17f5c68f2b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 30 Oct 2013 18:32:53 +0000 Subject: implement shutdown_timeout and expiry on graceful shutdown Otherwise, the server may stay running forever if a client chooses to stay forever (and there is no FD pressure). --- test/test_server.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/test_server.rb') diff --git a/test/test_server.rb b/test/test_server.rb index da57f8c..2cfee09 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -622,4 +622,37 @@ class TestServer < Testcase quit_wait(pid) FileUtils.rm_rf(tmpdir) end + + def test_persistent_shutdown_timeout; _persistent_shutdown(nil); end + def test_persistent_shutdown_timeout_mp; _persistent_shutdown(1); end + + def _persistent_shutdown(nr_workers) + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + pid = mkserver(cfg) do + ru = lambda { |e| [ 200, {'Content-Length'=>'2'}, %w(OK) ] } + cfg.instance_eval do + app(:rack, ru) { listen "#{host}:#{port}" } + stderr_path err.path + shutdown_timeout 1 + worker_processes(nr_workers) if nr_workers + end + end + c = get_tcp_client(host, port) + c.write "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" + assert_equal c, c.wait(30) + buf = "" + re = /\r\n\r\nOK\z/ + Timeout.timeout(30) do + begin + buf << c.readpartial(666) + end until re =~ buf + end + refute_match %r{Connection: close}, buf + assert_nil c.wait(0.001), "connection should still be alive" + Process.kill(:QUIT, pid) + _, status = Timeout.timeout(5) { Process.waitpid2(pid) } + assert status.success?, status.inspect + assert_nil c.wait(1) + assert_nil c.read(666) + end end -- cgit v1.2.3-24-ge0c7