From b6bd1df02decb24ee495689ab024d10f3ce6c1cc Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Thu, 2 Jun 2022 10:19:23 +0200 Subject: [PATCH] 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. --- lib/sidekiq_unique_jobs/testing.rb | 25 ++++++++++++++++--------- spec/sidekiq/testing_spec.rb | 11 +++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 spec/sidekiq/testing_spec.rb diff --git a/lib/sidekiq_unique_jobs/testing.rb b/lib/sidekiq_unique_jobs/testing.rb index 64dc47e3..be0fffba 100644 --- a/lib/sidekiq_unique_jobs/testing.rb +++ b/lib/sidekiq_unique_jobs/testing.rb @@ -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 # @@ -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 diff --git a/spec/sidekiq/testing_spec.rb b/spec/sidekiq/testing_spec.rb new file mode 100644 index 00000000..0478120d --- /dev/null +++ b/spec/sidekiq/testing_spec.rb @@ -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