test/unit/daemon_tests.rb in qs-0.3.0 vs test/unit/daemon_tests.rb in qs-0.4.0

- old
+ new

@@ -4,11 +4,11 @@ require 'dat-worker-pool/worker_pool_spy' require 'ns-options/assert_macros' require 'thread' require 'qs/client' require 'qs/queue' -require 'qs/redis_item' +require 'qs/queue_item' module Qs::Daemon class UnitTests < Assert::Context desc "Qs::Daemon" @@ -273,21 +273,21 @@ desc "running with a worker available and work" setup do @daemon = @daemon_class.new @thread = @daemon.start - @serialized_payload = Factory.string - @client_spy.append(@queue.redis_key, @serialized_payload) + @encoded_payload = Factory.string + @client_spy.append(@queue.redis_key, @encoded_payload) end subject{ @daemon } should "call dequeue on its client and add work to the worker pool" do call = @client_spy.calls.last assert_equal :block_dequeue, call.command exp = [subject.signals_redis_key, subject.queue_redis_keys, 0].flatten assert_equal exp, call.args - exp = Qs::RedisItem.new(@queue.redis_key, @serialized_payload) + exp = Qs::QueueItem.new(@queue.redis_key, @encoded_payload) assert_equal exp, @worker_pool_spy.work_items.first end end @@ -351,19 +351,19 @@ end @daemon = @daemon_class.new @thread = @daemon.start - @redis_item = Qs::RedisItem.new(Factory.string, Factory.string) - @worker_pool_spy.work_proc.call(@redis_item) + @queue_item = Qs::QueueItem.new(Factory.string, Factory.string) + @worker_pool_spy.work_proc.call(@queue_item) end subject{ @daemon } should "build and run a payload handler" do assert_not_nil @ph_spy assert_equal subject.daemon_data, @ph_spy.daemon_data - assert_equal @redis_item, @ph_spy.redis_item + assert_equal @queue_item, @ph_spy.queue_item end end class WorkerPoolOnWorkerErrorTests < InitSetupTests @@ -371,41 +371,41 @@ setup do @daemon = @daemon_class.new @thread = @daemon.start @exception = Factory.exception - @redis_item = Qs::RedisItem.new(Factory.string, Factory.string) + @queue_item = Qs::QueueItem.new(Factory.string, Factory.string) @callback = @worker_pool_spy.on_worker_error_callbacks.first end subject{ @daemon } - should "requeue the redis item if it wasn't started" do - @redis_item.started = false - @callback.call('worker', @exception, @redis_item) + should "requeue the queue item if it wasn't started" do + @queue_item.started = false + @callback.call('worker', @exception, @queue_item) call = @client_spy.calls.detect{ |c| c.command == :prepend } assert_not_nil call - assert_equal @redis_item.queue_redis_key, call.args.first - assert_equal @redis_item.serialized_payload, call.args.last + assert_equal @queue_item.queue_redis_key, call.args.first + assert_equal @queue_item.encoded_payload, call.args.last end - should "not requeue the redis item if it was started" do - @redis_item.started = true - @callback.call('worker', @exception, @redis_item) + should "not requeue the queue item if it was started" do + @queue_item.started = true + @callback.call('worker', @exception, @queue_item) assert_nil @client_spy.calls.detect{ |c| c.command == :prepend } end - should "do nothing if not passed a redis item" do + should "do nothing if not passed a queue item" do assert_nothing_raised{ @callback.call(@exception, nil) } end end class StopTests < StartTests desc "and then stopped" setup do - @redis_item = Qs::RedisItem.new(@queue.redis_key, Factory.string) - @worker_pool_spy.add_work(@redis_item) + @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string) + @worker_pool_spy.add_work(@queue_item) @daemon.stop true end should "shutdown the worker pool" do @@ -414,12 +414,12 @@ 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 + assert_equal @queue_item.queue_redis_key, call.args.first + assert_equal @queue_item.encoded_payload, call.args.last end should "stop the work loop thread" do assert_false @thread.alive? end @@ -447,12 +447,12 @@ end class HaltTests < StartTests desc "and then halted" setup do - @redis_item = Qs::RedisItem.new(@queue.redis_key, Factory.string) - @worker_pool_spy.add_work(@redis_item) + @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string) + @worker_pool_spy.add_work(@queue_item) @daemon.halt true end should "shutdown the worker pool with a 0 timeout" do @@ -461,12 +461,12 @@ 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 + assert_equal @queue_item.queue_redis_key, call.args.first + assert_equal @queue_item.encoded_payload, call.args.last end should "stop the work loop thread" do assert_false @thread.alive? end @@ -499,24 +499,24 @@ # 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) + @queue_item = Qs::QueueItem.new(@queue.redis_key, Factory.string) + @client_spy.append(@queue_item.queue_redis_key, @queue_item.encoded_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 + assert_equal @queue_item.queue_redis_key, call.args.first + assert_equal @queue_item.encoded_payload, call.args.last end should "stop the work loop thread" do assert_false @thread.alive? end @@ -665,14 +665,14 @@ end TestHandler = Class.new class PayloadHandlerSpy - attr_reader :daemon_data, :redis_item, :run_called + attr_reader :daemon_data, :queue_item, :run_called - def initialize(daemon_data, redis_item) + def initialize(daemon_data, queue_item) @daemon_data = daemon_data - @redis_item = redis_item + @queue_item = queue_item @run_called = false end def run @run_called = true