Skip to content

Commit

Permalink
spec changed according to last comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Robgra13 committed Oct 24, 2024
1 parent f1a192e commit 20e5c7f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
8 changes: 8 additions & 0 deletions lib/sidekiq_worker_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
require "rspec-sidekiq"
require "sidekiq-poison-pill-remedy"
require_relative "jobs/my_job"

Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' }
end

Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'] || 'redis://localhost:6379/0' }
end
36 changes: 12 additions & 24 deletions spec/sidekiq_poison_pill_remedy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,27 @@

RSpec.describe SidekiqPoisonPillRemedy do
before do
Sidekiq::Testing.inline!
allow(Sentry).to receive(:capture_message)
Sidekiq::Testing.fake!
end

it "moves job to poison_pill queue and logs message" do
puts "1"
puts "Starting test..."

jid = nil
expect do
jid = MyJob.perform_async("fail")
end.to raise_error(StandardError, "Forced failure for testing")
job_id = MyJob.perform_async(nil)

puts "Jobs in Queue: #{Sidekiq::Queue.new.size}"
puts "DeadSet size: #{Sidekiq::DeadSet.new.size}"

puts "Jobs in DeadSet after processing: #{Sidekiq::DeadSet.new.size}"

dead_set = Sidekiq::DeadSet.new
expect(dead_set.size).to eq(1)
job = dead_set.find_job(jid)
expect(Sidekiq::Queue.new.size).to eq(1)
expect(Sidekiq::Queue.new("poison_pill").size).to eq(0)
puts "2"

puts "4"
puts "Job JID: #{jid}"
expect(job).not_to be_nil
expect(job.klass).to eq("MyJob")
job = Sidekiq::Queue.new.find_job(job_id)

expect { described_class.remedy.call(nil, job) }.not_to raise_error
SidekiqPoisonPillRemedy.remedy.call(nil, job)

puts "DeadSet jobs: #{Sidekiq::DeadSet.new.size}"
puts "Queue jobs: #{Sidekiq::Queue.new.size}"
puts "Jobs in Queue: #{Sidekiq::Queue.new.size}"
puts "3"

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}"
expect(Sidekiq::Queue.new.size).to eq(0)
expect(Sidekiq::Queue.new("poison_pill").size).to eq(1)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f }

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

Expand Down
6 changes: 5 additions & 1 deletion spec/support/my_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class MyJob
sidekiq_options retry: 3

def perform(arg)
raise StandardError, "Forced failure for testing" if arg == "fail"
if arg.nil?
raise StandardError, "Job was called with nil argument"
else
puts "Job executed successfully with argument: #{arg}"
end
end
end

0 comments on commit 20e5c7f

Please sign in to comment.