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)
97 def test_valid_should_return_false_if_no_name
106 def test_valid_should_return_false_if_no_start
114 def test_valid_should_return_false_if_self_daemonized_and_no_stop
123 def test_valid_should_return_false_if_self_daemonized_and_log
136 def test_default_pid_file
137 assert_equal File.join(God.pid_file_directory, 'foo.pid'), @p.default_pid_file
141 # These actually excercise call_action in the back at this point - Kev
143 def test_call_action_with_string_should_fork_exec
144 @p.start = "do something"
145 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
147 Process.expects(:waitpid)
148 @p.call_action(:start)
151 def test_call_action_with_lambda_should_call
152 cmd = lambda { puts "Hi" }
155 @p.call_action(:start)
158 def test_call_action_without_pid_should_write_pid
159 # Only for start, restart
160 [:start, :restart].each do |action|
161 @p = God::Process.new
163 @p.stubs(:test).returns true
164 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
166 Process.expects(:waitpid)
167 File.expects(:open).with(@p.default_pid_file, 'w')
168 @p.send("#{action}=", "run")
169 @p.call_action(action)
173 def test_call_action_should_not_write_pid_for_stop
175 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
177 Process.expects(:waitpid)
178 File.expects(:open).times(0)
180 @p.call_action(:stop)
183 def test_call_action_with_invalid_command_class_should_raise
189 assert_raise NotImplementedError do
190 @p.call_action(:start)
194 # start!/stop!/restart!
196 def test_start_stop_restart_bang
197 [:start, :stop, :restart].each do |x|
198 @p.expects(:call_action).with(x)