From f251b9f15126640523f833940b36dec80e2ff6ad Mon Sep 17 00:00:00 2001 From: Ben Kirzhner Date: Mon, 7 Jan 2013 11:26:02 -0800 Subject: [PATCH] Implement integration test for retrying expected failures --- spec/integration/worker_spec.rb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/spec/integration/worker_spec.rb b/spec/integration/worker_spec.rb index d3ac96a6..b73a38fe 100644 --- a/spec/integration/worker_spec.rb +++ b/spec/integration/worker_spec.rb @@ -3,10 +3,23 @@ require 'yaml' require 'qless/worker' require 'qless' +require 'qless/retry_exceptions' class WorkerIntegrationJob def self.perform(job) - Redis.connect(:url => job['redis_url']).rpush('worker_integration_job', job['word']) + Redis.connect(url: job['redis_url']).rpush('worker_integration_job', job['word']) + end +end + +class RetryIntegrationJob + extend Qless::RetryExceptions + + Kaboom = Class.new(StandardError) + retry_on Kaboom + + def self.perform(job) + Redis.connect(url: job['redis_url']).incr('retry_integration_job_count') + raise Kaboom end end @@ -42,6 +55,21 @@ def start_worker(run_as_single_process) it_behaves_like 'a running worker', '1' - it 'will retry and eventually fail a repeatedly failing job' + it 'will retry and eventually fail a repeatedly failing job' do + queue = client.queues["main"] + jid = queue.put(RetryIntegrationJob, {}, retries: 10) + Qless::Worker.new( + client, + Qless::JobReservers::RoundRobin.new([queue]), + run_as_a_single_process: true + ).work(0) + + job = client.jobs[jid] + + job.state.should eq('failed') + job.retries_left.should eq(-1) + job.original_retries.should eq(10) + client.redis.get('retry_integration_job_count').should eq('11') + end end