about summary refs log tree commit homepage
path: root/test/test_server.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-30 18:32:53 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-31 05:04:30 +0000
commit3741b945dcaf2e432f9e0088b4553d17f5c68f2b (patch)
tree716e849598eb744e488b1de68309b92c817a0703 /test/test_server.rb
parentbfe699496ced8f73f659da0f0857fda614fb40b6 (diff)
downloadyahns-3741b945dcaf2e432f9e0088b4553d17f5c68f2b.tar.gz
Otherwise, the server may stay running forever if a client chooses
to stay forever (and there is no FD pressure).
Diffstat (limited to 'test/test_server.rb')
-rw-r--r--test/test_server.rb33
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