Skip to content

Commit

Permalink
Fix edge case in ruby reaper
Browse files Browse the repository at this point in the history
Closes #653

The problem was that the reaper returns nil instead of the memo. Many thanks to @francesmcmullin for the wonderfully detailed report and investigation. Now we have a regression test for this behavior.
  • Loading branch information
mhenrixon committed Nov 30, 2021
1 parent 94a203a commit 9555540
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def orphans
next if belongs_to_job?(digest)

memo << digest
break if memo.size >= reaper_count
break memo if memo.size >= reaper_count
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/sidekiq_unique_jobs/orphans/ruby_reaper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@
describe "#orphans" do
subject(:orphans) { service.orphans }

context "when reaping more jobs than reaper_count" do
let(:digest_one) { "uniquejobs:digest1" }
let(:digest_two) { "uniquejobs:digest2" }
let(:digest_three) { "uniquejobs:digest3" }
let(:job_id_one) { "jobid1" }
let(:job_id_two) { "jobid2" }
let(:job_id_three) { "jobid3" }

before do
SidekiqUniqueJobs::Lock.create(digest_one, job_id_one)
SidekiqUniqueJobs::Lock.create(digest_two, job_id_two)
SidekiqUniqueJobs::Lock.create(digest_three, job_id_three)
end

it 'returns the first digest' do
SidekiqUniqueJobs.use_config(reaper_count: 1) do
expect(orphans.size).to eq(1)
expect([digest_one, digest_two, digest_three]).to include(orphans.first)
end
end
end

context "when scheduled" do
let(:item) { raw_item.merge("at" => Time.now.to_f + 3_600) }

Expand Down

0 comments on commit 9555540

Please sign in to comment.