From e75de4b28b19e9ac79083bba4b55bcb4c93b207d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 2 Sep 2009 21:18:20 -0700 Subject: test to ensure stderr goes *somewhere* when daemonized Followup to commit 7f74a16406c92c4362ac20af4ccb8bc821cf978b, we want to ensure error messages do not get swallowed up into /dev/null when daemonizing; so we defer the default redirects to "/dev/null" to as late as possible. --- test/exec/test_exec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb index cf7ef28..19177fe 100644 --- a/test/exec/test_exec.rb +++ b/test/exec/test_exec.rb @@ -604,6 +604,26 @@ end reexec_usr2_quit_test(new_pid, pid_file) end + def test_daemonize_redirect_fail + pid_file = "#{@tmpdir}/test.pid" + log = Tempfile.new('unicorn_test_log') + ucfg = Tempfile.new('unicorn_test_config') + ucfg.syswrite("pid #{pid_file}\"\n") + err = Tempfile.new('stderr') + out = Tempfile.new('stdout ') + + File.open("config.ru", "wb") { |fp| fp.syswrite(HI) } + pid = xfork do + $stderr.reopen(err.path, "a") + $stdout.reopen(out.path, "a") + exec($unicorn_bin, "-D", "-l#{@addr}:#{@port}", "-c#{ucfg.path}") + end + pid, status = Process.waitpid2(pid) + assert status.success?, "original process exited successfully" + sleep 1 # can't waitpid on a daemonized process :< + assert err.stat.size > 0 + end + def test_reexec_fd_leak unless RUBY_PLATFORM =~ /linux/ # Solaris may work, too, but I forget... warn "FD leak test only works on Linux at the moment" -- cgit v1.2.3-24-ge0c7