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-26 02:45:49 +0000
committerEric Wong <e@80x24.org>2013-10-26 02:45:49 +0000
commit50b9493b07023a8d6502e620657fa209b6aa74ef (patch)
treed191cf061b5bd7b24f28209da170acebde614e65 /test/test_server.rb
parent5d5377e094745ee76cd066d2244c52b40647d1cc (diff)
downloadyahns-50b9493b07023a8d6502e620657fa209b6aa74ef.tar.gz
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.
Diffstat (limited to 'test/test_server.rb')
-rw-r--r--test/test_server.rb58
1 files changed, 58 insertions, 0 deletions
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