Permalink
Browse files

Implement integration test for retrying expected failures

  • Loading branch information...
bkirz committed Jan 7, 2013
1 parent 391491d commit f251b9f15126640523f833940b36dec80e2ff6ad
Showing with 30 additions and 2 deletions.
  1. +30 −2 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

0 comments on commit f251b9f

Please sign in to comment.