test/unit/process_tests.rb in qs-0.2.0 vs test/unit/process_tests.rb in qs-0.3.0
- old
+ new
@@ -11,10 +11,14 @@
setup do
@process_class = Qs::Process
end
subject{ @process_class }
+ should "know its wait for signals timeout" do
+ assert_equal 15, WAIT_FOR_SIGNALS_TIMEOUT
+ end
+
end
class InitTests < UnitTests
desc "when init"
setup do
@@ -115,13 +119,24 @@
end
class RunTests < RunSetupTests
desc "and run"
setup do
+ @wait_timeout = nil
+ Assert.stub(@process.signal_io, :wait) do |timeout|
+ @wait_timeout = timeout
+ sleep 0.1
+ false
+ end
+
@thread = Thread.new{ @process.run }
@thread.join(0.1)
end
+ teardown do
+ # manually unstub or the process thread will hang forever
+ Assert.unstub(@process.signal_io, :wait)
+ end
should "not daemonize the process" do
assert_false @daemonize_called
end
@@ -141,10 +156,11 @@
should "start the daemon" do
assert_true @daemon_spy.start_called
end
should "sleep its thread waiting for signals" do
+ assert_equal WAIT_FOR_SIGNALS_TIMEOUT, @wait_timeout
assert_equal 'sleep', @thread.status
end
should "not run the restart cmd" do
assert_false @restart_cmd_spy.run_called
@@ -260,10 +276,34 @@
assert_true @restart_cmd_spy.run_called
end
end
+ class RunWithDaemonCrashTests < RunSetupTests
+ desc "and run with the daemon crashing"
+ setup do
+ # lower the time it sleeps so it loops and restarts the daemon quicker
+ Assert.stub(@process.signal_io, :wait) do |timeout|
+ sleep 0.1
+ false
+ end
+
+ @thread = Thread.new{ @process.run }
+ @daemon_spy.start_called = false
+ @thread.join(0.1)
+ end
+ teardown do
+ # manually unstub or the process thread will hang forever
+ Assert.unstub(@process.signal_io, :wait)
+ end
+
+ should "re-start its daemon" do
+ assert_true @daemon_spy.start_called
+ end
+
+ end
+
class RunWithInvalidSignalTests < RunSetupTests
desc "and run with unsupported signals"
setup do
# ruby throws an argument error if the OS doesn't support a signal
Assert.stub(::Signal, :trap){ raise ArgumentError }
@@ -399,9 +439,13 @@
end
def halt(*args)
@halt_args = args
@halt_called = true
+ end
+
+ def running?
+ !!@start_called
end
end
class RestartCmdSpy
attr_reader :run_called