Skip to content

Commit

Permalink
Implement integration test for retrying expected failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bkirz committed Jan 7, 2013
1 parent 391491d commit f251b9f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions spec/integration/worker_spec.rb
Expand Up @@ -3,10 +3,23 @@
require 'yaml' require 'yaml'
require 'qless/worker' require 'qless/worker'
require 'qless' require 'qless'
require 'qless/retry_exceptions'


class WorkerIntegrationJob class WorkerIntegrationJob
def self.perform(job) 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
end end


Expand Down Expand Up @@ -42,6 +55,21 @@ def start_worker(run_as_single_process)


it_behaves_like 'a running worker', '1' 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 end


0 comments on commit f251b9f

Please sign in to comment.