diff options
Diffstat (limited to 'test/cmogstored-cfg.rb')
-rw-r--r-- | test/cmogstored-cfg.rb | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/test/cmogstored-cfg.rb b/test/cmogstored-cfg.rb index 77efd7c..07dfc6a 100644 --- a/test/cmogstored-cfg.rb +++ b/test/cmogstored-cfg.rb @@ -487,7 +487,7 @@ class TestCmogstoredConfig < Test::Unit::TestCase cfg.puts "mgmtlisten = #@host:#@port" cfg.puts "docroot = #@tmpdir" cfg.puts "pidfile = #{basename}" - cfg.puts "daemonize" + cfg.puts "daemonize = 1" cfg.flush @cmd << "--config=#{cfg.path}" tmp = Tempfile.new("err") @@ -504,4 +504,50 @@ class TestCmogstoredConfig < Test::Unit::TestCase assert_match(/pidfile=#{basename} must use an absolute/, lines) assert_match(/relative paths are incompatible with --daemonize/, lines) end + + def test_daemonized_config_has_pidfile + pid = Tempfile.new("pid") + cfg = Tempfile.new("cfg") + cfg.puts "mgmtlisten = #@host:#@port" + cfg.puts "docroot = #@tmpdir" + cfg.puts "pidfile = #{pid.path}" + cfg.puts "daemonize = 1" + cfg.flush + @cmd << "--config=#{cfg.path}" + tmp = Tempfile.new("err") + @pid = fork do + expand_suppressions!(@cmd) + $stderr.reopen(tmp) + exec(*@cmd) + end + _, status = Process.waitpid2(@pid) + assert status.success?, status.inspect + pre_kill + read_pid = File.read(pid.path) + assert_match(%r{\A\d+\n\z}, read_pid) + read_pid = read_pid.to_i + assert_equal 1, Process.kill(0, read_pid) + assert_equal 1, Process.kill(:QUIT, read_pid) + end + + def test_daemonized_0 + pid = Tempfile.new("pid") + cfg = Tempfile.new("cfg") + cfg.puts "mgmtlisten = #@host:#@port" + cfg.puts "docroot = #@tmpdir" + cfg.puts "pidfile = #{pid.path}" + cfg.puts "daemonize = 0" + cfg.flush + @cmd << "--config=#{cfg.path}" + tmp = Tempfile.new("err") + @pid = fork do + expand_suppressions!(@cmd) + $stderr.reopen(tmp) + exec(*@cmd) + end + pre_kill + read_pid = File.read(pid.path) + assert_equal @pid, read_pid.to_i + assert_equal 1, Process.kill(:QUIT, @pid) + end end |