Skip to content

Commit

Permalink
changes in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Robgra13 committed Oct 23, 2024
1 parent 8b20c9e commit 2d4e506
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
26 changes: 17 additions & 9 deletions spec/sidekiq_poison_pill_remedy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@
require 'sidekiq'
require 'sidekiq-poison-pill-remedy'
require 'support/my_job'
require 'sidekiq/api'

RSpec.describe SidekiqPoisonPillRemedy do
let(:job_args) { ['test_argument'] }
let(:jid) { MyJob.perform_async(*job_args) }

before do
Sidekiq::Testing.fake!
end

it 'moves job to poison_pill queue and logs message' do
begin
MyJob.new.perform('fail')
rescue StandardError
nil
end
puts '1'
jid = MyJob.perform_async('fail')
puts "Jobs in Queue: #{Sidekiq::Queue.new.size}"
puts "DeadSet size: #{Sidekiq::DeadSet.new.size}"
puts '2'

MyJob.drain
puts '3'

job = Sidekiq::DeadSet.new.find_job(jid)
puts '4'
puts "Job JID: #{jid}"
puts "DeadSet size: #{Sidekiq::DeadSet.new.size}"

expect(job).not_to be_nil
expect(job.klass).to eq('MyJob')

SidekiqPoisonPillRemedy.remedy.call(nil, job)

puts "DeadSet jobs: #{Sidekiq::DeadSet.new.size}"
puts "Queue jobs: #{Sidekiq::Queue.new.size}"
puts "Job JID: #{jid}"

poison_pill_job = Sidekiq::Queue.new('poison_pill').find_job(job.jid)
expect(poison_pill_job).not_to be_nil
puts "Poison Pill Job JID: #{poison_pill_job.jid}"
end
end
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
require 'sidekiq'
require 'sidekiq-poison-pill-remedy'

Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }

RSpec.configure do |config|
Sidekiq::Testing.inline!
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'

Expand All @@ -21,6 +24,4 @@
config.before(:all) do
ENV['REDIS_URL'] ||= 'redis://localhost:6379/1'
end

Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }
end
10 changes: 8 additions & 2 deletions spec/support/my_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class MyJob
include Sidekiq::Worker
include Sidekiq::Job
sidekiq_options retry: 0

def perform(arg)
raise 'An error occurred!' if arg == 'fail'
if arg == 'fail'
Sidekiq.logger.error('Forced failure for testing')

else
'surprise'
end
end
end

0 comments on commit 2d4e506

Please sign in to comment.