From c2e51916201f4f29a72e21320b38181ee1eaa697 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 May 2009 02:07:40 +0000 Subject: Instant shutdown signals really mean instant shutdown Use SIGQUIT if you're going to be nice and do graceful shutdowns. Sometimes people run real applications on this server and SIGINT/SIGTERM get lost/trapped when Object is rescued and that is not good. Also make sure we break out of the loop properly when the master is dead. Testcases added for both SIGINT and dead master handling. --- test/unit/test_signals.rb | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test') diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb index d8af285..ca81d3e 100644 --- a/test/unit/test_signals.rb +++ b/test/unit/test_signals.rb @@ -37,6 +37,58 @@ class SignalsTest < Test::Unit::TestCase @server = nil end + def test_worker_dies_on_dead_master + pid = fork { + app = lambda { |env| [ 200, {'X-Pid' => "#$$" }, [] ] } + opts = @server_opts.merge(:timeout => 2) + redirect_test_io { HttpServer.new(app, opts).start.join } + } + child = sock = buf = t0 = nil + assert_nothing_raised do + wait_master_ready("test_stderr.#{pid}.log") + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + buf = sock.readpartial(4096) + sock.close + buf =~ /\bX-Pid: (\d+)\b/ or raise Exception + child = $1.to_i + Process.kill(:KILL, pid) + Process.waitpid(pid) + t0 = Time.now + end + assert child + assert t0 + assert_raises(Errno::ESRCH) { loop { Process.kill(0, child); sleep 0.2 } } + assert((Time.now - t0) < 60) + end + + def test_sleepy_kill + rd, wr = IO.pipe + pid = fork { + rd.close + app = lambda { |env| wr.syswrite('.'); sleep; [ 200, {}, [] ] } + redirect_test_io { HttpServer.new(app, @server_opts).start.join } + } + sock = buf = nil + wr.close + assert_nothing_raised do + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + buf = rd.readpartial(1) + wait_master_ready("test_stderr.#{pid}.log") + Process.kill(:INT, pid) + Process.waitpid(pid) + end + assert_equal '.', buf + buf = nil + assert_raises(EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL, + Errno::EBADF) do + buf = sock.sysread(4096) + end + assert_nil buf + ensure + end + def test_timeout_slow_response pid = fork { app = lambda { |env| sleep } -- cgit v1.2.3-24-ge0c7