From ac4537afc4eddfb68bc7807f7a6140afb7160328 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 16 Sep 2009 12:11:56 -0700 Subject: test_exec: add extra tests for HUP and preload_app Just to ensure we handle HUP correctly since preload_app changes the behavior of HUP handling a bit. --- test/exec/test_exec.rb | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) 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 -- cgit v1.2.3-24-ge0c7