about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-09-16 12:11:56 -0700
committerEric Wong <normalperson@yhbt.net>2009-09-16 12:18:16 -0700
commitac4537afc4eddfb68bc7807f7a6140afb7160328 (patch)
treecae7934e69b8760eb5968173a02d7c6c71f32684 /test
parentbd075c8f746dfa97e3e2fe74a262e747806cf772 (diff)
downloadunicorn-ac4537afc4eddfb68bc7807f7a6140afb7160328.tar.gz
Just to ensure we handle HUP correctly since preload_app
changes the behavior of HUP handling a bit.
Diffstat (limited to 'test')
-rw-r--r--test/exec/test_exec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index 7a5f3bf..3173d9a 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
@@ -697,4 +697,62 @@ end
     wait_for_death(pid)
   end
 
+  def hup_test_common(preload)
+    File.open("config.ru", "wb") { |fp| fp.syswrite(HI.gsub("HI", '#$$')) }
+    pid_file = Tempfile.new('pid')
+    ucfg = Tempfile.new('unicorn_test_config')
+    ucfg.syswrite("listen '#@addr:#@port'\n")
+    ucfg.syswrite("pid '#{pid_file.path}'\n")
+    ucfg.syswrite("preload_app true\n") if preload
+    ucfg.syswrite("stderr_path 'test_stderr.#$$.log'\n")
+    ucfg.syswrite("stdout_path 'test_stdout.#$$.log'\n")
+    pid = xfork {
+      redirect_test_io { exec($unicorn_bin, "-D", "-c", ucfg.path) }
+    }
+    _, status = Process.waitpid2(pid)
+    assert status.success?
+    wait_master_ready("test_stderr.#$$.log")
+    wait_workers_ready("test_stderr.#$$.log", 1)
+    uri = URI.parse("http://#@addr:#@port/")
+    pids = Tempfile.new('worker_pids')
+    hitter = fork {
+      bodies = Hash.new(0)
+      at_exit { pids.syswrite(bodies.inspect) }
+      trap(:TERM) { exit(0) }
+      loop {
+        rv = Net::HTTP.get(uri)
+        pid = rv.to_i
+        exit!(1) if pid <= 0
+        bodies[pid] += 1
+      }
+    }
+    sleep 1 # racy
+    daemon_pid = pid_file.read.to_i
+    assert daemon_pid > 0
+    Process.kill(:HUP, daemon_pid)
+    sleep 1 # racy
+    assert_nothing_raised { Process.kill(:TERM, hitter) }
+    _, hitter_status = Process.waitpid2(hitter)
+    assert hitter_status.success?
+    pids.sysseek(0)
+    pids = eval(pids.read)
+    assert_kind_of(Hash, pids)
+    assert_equal 2, pids.size
+    pids.keys.each { |x|
+      assert_kind_of(Integer, x)
+      assert x > 0
+      assert pids[x] > 0
+    }
+    assert_nothing_raised { Process.kill(:QUIT, daemon_pid) }
+    wait_for_death(daemon_pid)
+  end
+
+  def test_preload_app_hup
+    hup_test_common(true)
+  end
+
+  def test_hup
+    hup_test_common(false)
+  end
+
 end if do_test