test/unit/daemon_tests.rb in qs-0.1.0 vs test/unit/daemon_tests.rb in qs-0.2.0
- old
+ new
@@ -284,10 +284,38 @@
assert_equal exp, @worker_pool_spy.work_items.first
end
end
+ class RunningWithErrorWhileDequeuingTests < InitSetupTests
+ desc "running with an error while dequeueing"
+ setup do
+ @daemon = @daemon_class.new
+ @thread = @daemon.start
+
+ @block_dequeue_calls = 0
+ Assert.stub(@client_spy, :block_dequeue) do
+ @block_dequeue_calls += 1
+ raise RuntimeError
+ end
+ # cause the daemon to loop, its sleeping on the original block_dequeue
+ # call that happened before the stub
+ @client_spy.append(@queue.redis_key, Factory.string)
+ @thread.join(0.1)
+ end
+ subject{ @daemon }
+
+ should "not cause the thread to exit" do
+ assert_true @thread.alive?
+ assert_equal 1, @block_dequeue_calls
+ @thread.join(1)
+ assert_true @thread.alive?
+ assert_equal 2, @block_dequeue_calls
+ end
+
+ end
+
class RunningWithMultipleQueuesTests < InitSetupTests
desc "running with multiple queues"
setup do
@other_queue = Qs::Queue.new{ name(Factory.string) }
@daemon_class.queue @other_queue
@@ -458,10 +486,44 @@
assert_false subject.running?
end
end
+ class WorkLoopErrorTests < StartTests
+ desc "with a work loop error"
+ setup do
+ # cause a non-dequeue error
+ Assert.stub(@worker_pool_spy, :worker_available?){ raise RuntimeError }
+
+ # cause the daemon to loop, its sleeping on the original block_dequeue
+ # call that happened before the stub
+ @redis_item = Qs::RedisItem.new(@queue.redis_key, Factory.string)
+ @client_spy.append(@redis_item.queue_redis_key, @redis_item.serialized_payload)
+ end
+
+ should "shutdown the worker pool" do
+ assert_true @worker_pool_spy.shutdown_called
+ assert_equal @daemon_class.shutdown_timeout, @worker_pool_spy.shutdown_timeout
+ end
+
+ should "requeue any work left on the pool" do
+ call = @client_spy.calls.last
+ assert_equal :prepend, call.command
+ assert_equal @redis_item.queue_redis_key, call.args.first
+ assert_equal @redis_item.serialized_payload, call.args.last
+ end
+
+ should "stop the work loop thread" do
+ assert_false @thread.alive?
+ end
+
+ should "not be running" do
+ assert_false subject.running?
+ end
+
+ end
+
class ConfigurationTests < UnitTests
include NsOptions::AssertMacros
desc "Configuration"
setup do
@@ -559,57 +621,9 @@
subject.init_procs << proc{ called += 1 }
subject.validate!
assert_equal 1, called
subject.validate!
assert_equal 1, called
- end
-
- end
-
- class IOPipeTests < UnitTests
- desc "IOPipe"
- setup do
- @io = IOPipe.new
- end
- subject{ @io }
-
- should have_readers :reader, :writer
- should have_imeths :wait, :signal
- should have_imeths :setup, :teardown
-
- should "default its reader and writer" do
- assert_same IOPipe::NULL, subject.reader
- assert_same IOPipe::NULL, subject.writer
- end
-
- should "be able to wait until signalled" do
- subject.setup
-
- thread = Thread.new{ subject.wait }
- thread.join(0.1)
- assert_equal 'sleep', thread.status
-
- subject.signal
- thread.join
- assert_false thread.status
- end
-
- should "set its reader and writer to an IO pipe when setup" do
- subject.setup
- assert_instance_of ::IO, subject.reader
- assert_instance_of ::IO, subject.writer
- end
-
- should "close its reader/writer and set them to defaults when torn down" do
- subject.setup
- reader = subject.reader
- writer = subject.writer
-
- subject.teardown
- assert_true reader.closed?
- assert_true writer.closed?
- assert_same IOPipe::NULL, subject.reader
- assert_same IOPipe::NULL, subject.writer
end
end
class SignalTests < UnitTests