Skip to content

Commit

Permalink
Fix Sidekiq::Worker.clear_all override not being applied (#714)
Browse files Browse the repository at this point in the history
* Fix Sidekiq::Worker.clear_all override not being applied

Since the method is defined as a singleton the testing override needs to
be prepended to the singleton class.

* Rename `testing_spec` to `worker_spec`

`
  • Loading branch information
dsander committed Jul 1, 2022
1 parent bf573a4 commit 10d08bd
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/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

RSpec.describe "Sidekiq::Worker" do
describe "#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 10d08bd

Please sign in to comment.