From 50b9493b07023a8d6502e620657fa209b6aa74ef Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Oct 2013 02:45:49 +0000 Subject: fix SIGCHLD w/o workers + PID file renames We'll hit SIGCHLD if our reexec process fails on us, so the non-MP server must handle it, too. We discovered this bug while porting the PID file renaming changes from unicorn. --- test/test_server.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/test_server.rb') diff --git a/test/test_server.rb b/test/test_server.rb index d10a70e..d34ed2a 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -402,4 +402,62 @@ class TestServer < Testcase ensure quit_wait(pid) end + + def test_pidfile_usr2 + tmpdir = Dir.mktmpdir + pidf = "#{tmpdir}/pid" + old = "#{pidf}.oldbin" + err = @err + cfg = Yahns::Config.new + host, port = @srv.addr[3], @srv.addr[1] + cfg.instance_eval do + GTL.synchronize { + app(:rack, lambda { |_| [ 200, {}, [] ] }) { listen "#{host}:#{port}" } + pid pidf + } + stderr_path err.path + end + pid = mkserver(cfg) do + Yahns::START[0] = "sh" + Yahns::START[:argv] = [ '-c', "echo $$ > #{pidf}; sleep 10" ] + end + + # ensure server is running + c = get_tcp_client(host, port) + c.write("GET / HTTP/1.0\r\n\r\n") + buf = Timeout.timeout(10) { c.read } + assert_match(/Connection: close/, buf) + c.close + + assert_equal pid, File.read(pidf).to_i + before = File.stat(pidf) + + # start the upgrade + Process.kill(:USR2, pid) + Timeout.timeout(10) { sleep(0.01) until File.exist?(old) } + after = File.stat(old) + assert_equal after.ino, before.ino + Timeout.timeout(10) { sleep(0.01) until File.exist?(pidf) } + new = File.read(pidf).to_i + refute_equal pid, new + + # abort the upgrade (just wait for it to finish) + Process.kill(:TERM, new) + poke_until_dead(new) + + # ensure reversion is OK + Timeout.timeout(10) { sleep(0.01) while File.exist?(old) } + after = File.stat(pidf) + assert_equal before.ino, after.ino + assert_equal before.mtime, after.mtime + assert_equal pid, File.read(pidf).to_i + + lines = File.readlines(err.path).grep(/ERROR/) + assert_equal 1, lines.size + assert_match(/reaped/, lines[0], lines) + File.truncate(err.path, 0) + ensure + quit_wait(pid) + FileUtils.rm_rf(tmpdir) + end end -- cgit v1.2.3-24-ge0c7