diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-05-04 02:07:40 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-05-03 21:22:48 -0700 |
commit | c2e51916201f4f29a72e21320b38181ee1eaa697 (patch) | |
tree | 25cbe6fbfbcfff7f68c654873ea2c5ac422afd2d /test/unit | |
parent | a7830cce6a3bf13996fe42503164437fb9809909 (diff) | |
download | unicorn-c2e51916201f4f29a72e21320b38181ee1eaa697.tar.gz |
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.
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/test_signals.rb | 52 |
1 files changed, 52 insertions, 0 deletions
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 } |