test/test_worker.rb in kthxbye-1.2.1 vs test/test_worker.rb in kthxbye-1.3.0

- old
+ new

@@ -1,10 +1,10 @@ class TestWorker < Test::Unit::TestCase context "See Kthxbye::Worker" do setup do - Kthxbye::Config.setup(:verbose => false, :redis_port => 9876) + Kthxbye::Config.setup(:verbose => false, :redis_port => 9876, :attempts => 1) Kthxbye.redis.flushall @id = Kthxbye.enqueue( "test", SimpleJob, 1, 2 ) @worker = Kthxbye::Worker.new("test", 0) end @@ -126,9 +126,32 @@ should "find the current job" do @worker.run do assert_equal ({'job_id' => @id, 'started' => Time.now.to_s}), Kthxbye::Worker.working_on(@worker.id) end + end + + should "report system stats" do + Kthxbye.enqueue( "test", BadJob ) + assert_equal 0, @worker.processed + assert_equal 0, @worker.failed + + @worker.run + + assert_equal 2, Kthxbye::Stats["processed"] + assert_equal 1, Kthxbye::Stats["failures"] + end + + should "track failures" do + Kthxbye.enqueue( "test", BadJob ) + Kthxbye.enqueue( "test", BadJob ) + + 3.times do + job = @worker.grab_job + @worker.perform(job) + end + + assert_equal 2, @worker.failed end should "requeue a job and report error if worker is killed mid-process" do @worker.working( Kthxbye::Job.find( @id, "test" ) ) @worker.unregister_worker