1 require File.dirname(__FILE__) + '/helper'
6 raise "You forgot to stub fork"
10 raise "You forgot to stub exec"
15 class TestProcessChild < Test::Unit::TestCase
20 @p.stubs(:test).returns true # so we don't try to mkdir_p
21 Process.stubs(:detach) # because we stub fork
26 def test_valid_should_return_true_if_auto_daemonized_and_log
33 def test_valid_should_return_true_if_auto_daemonized_and_no_stop
40 def test_valid_should_return_true_if_uid_exists
48 def test_valid_should_return_true_if_uid_does_not_exists
58 def test_valid_should_return_true_if_gid_exists
66 def test_valid_should_return_true_if_gid_does_not_exists
77 class TestProcessDaemon < Test::Unit::TestCase
82 @p.pid_file = 'blah.pid'
83 @p.stubs(:test).returns true # so we don't try to mkdir_p
84 Process.stubs(:detach) # because we stub fork
89 def test_alive_should_call_system_process_exists
90 File.expects(:read).with('blah.pid').returns('1234')
91 System::Process.any_instance.expects(:exists?).returns(false)
95 def test_alive_should_return_false_if_no_such_file
96 File.expects(:read).with('blah.pid').raises(Errno::ENOENT)
102 def test_valid_should_return_false_if_no_start
110 def test_valid_should_return_false_if_self_daemonized_and_no_stop
119 def test_valid_should_return_false_if_self_daemonized_and_log
132 def test_default_pid_file
133 assert_equal File.join(God.pid_file_directory, 'foo.pid'), @p.default_pid_file
137 # These actually excercise call_action in the back at this point - Kev
139 def test_call_action_with_string_should_fork_exec
140 @p.start = "do something"
141 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
143 Process.expects(:waitpid)
144 @p.call_action(:start)
147 def test_call_action_with_lambda_should_call
148 cmd = lambda { puts "Hi" }
151 @p.call_action(:start)
154 def test_call_action_without_pid_should_write_pid
155 # Only for start, restart
156 [:start, :restart].each do |action|
157 @p = God::Process.new
159 @p.stubs(:test).returns true
160 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
162 Process.expects(:waitpid)
163 File.expects(:open).with(@p.default_pid_file, 'w')
164 @p.send("#{action}=", "run")
165 @p.call_action(action)
169 def test_call_action_should_not_write_pid_for_stop
171 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
173 Process.expects(:waitpid)
174 File.expects(:open).times(0)
176 @p.call_action(:stop)
179 def test_call_action_with_invalid_command_class_should_raise
185 assert_raise NotImplementedError do
186 @p.call_action(:start)
190 # start!/stop!/restart!
192 def test_start_stop_restart_bang
193 [:start, :stop, :restart].each do |x|
194 @p.expects(:call_action).with(x)