diff --git a/lib/sidekiq_worker_loader.rb b/lib/sidekiq_worker_loader.rb index 3e8444b..7fcf196 100644 --- a/lib/sidekiq_worker_loader.rb +++ b/lib/sidekiq_worker_loader.rb @@ -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 diff --git a/spec/sidekiq_poison_pill_remedy_spec.rb b/spec/sidekiq_poison_pill_remedy_spec.rb index 858bae5..526af06 100644 --- a/spec/sidekiq_poison_pill_remedy_spec.rb +++ b/spec/sidekiq_poison_pill_remedy_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fad5a51..70faa9a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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" diff --git a/spec/support/my_job.rb b/spec/support/my_job.rb index 0137189..c0d57c7 100644 --- a/spec/support/my_job.rb +++ b/spec/support/my_job.rb @@ -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