diff options
Diffstat (limited to 'test/test_server.rb')
-rw-r--r-- | test/test_server.rb | 33 |
1 files changed, 33 insertions, 0 deletions
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 |