Skip to content

Commit

Permalink
Fix Sidekiq::Worker.clear_all override not being applied
Browse files Browse the repository at this point in the history
Since the method is defined as a singleton the testing override needs to
be prepended to the singleton class.
  • Loading branch information
dsander committed Jun 2, 2022
1 parent 2eb4b99 commit b6bd1df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/sidekiq_unique_jobs/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ def sidekiq_options(options = {})
super(options)
end

#
# Clears all jobs for this worker and removes all locks
#
def clear_all
super

SidekiqUniqueJobs::Digests.new.delete_by_pattern("*", count: 10_000)
end

#
# Prepends deletion of locks to clear
#
Expand All @@ -124,5 +115,21 @@ def clear
module ClassMethods
prepend Overrides::ClassMethods
end

#
# Prepends singleton methods to Sidekiq::Worker
#
module SignletonOverrides
#
# Clears all jobs for this worker and removes all locks
#
def clear_all
super

SidekiqUniqueJobs::Digests.new.delete_by_pattern("*", count: 10_000)
end
end

singleton_class.prepend SignletonOverrides
end
end
11 changes: 11 additions & 0 deletions spec/sidekiq/testing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

RSpec.describe "sidekiq/testing" do
describe "Sidekiq::Worker.clear_all" do
it "unlocks all unique locks" do
expect(UntilAndWhileExecutingJob.perform_async).not_to be_nil
Sidekiq::Worker.clear_all
expect(UntilAndWhileExecutingJob.perform_async).not_to be_nil
end
end
end

0 comments on commit b6bd1df

Please sign in to comment.