diff --git a/spec/support/workers/until_and_while_executing_reject_job.rb b/spec/support/workers/until_and_while_executing_reject_job.rb new file mode 100644 index 00000000..4e9c2133 --- /dev/null +++ b/spec/support/workers/until_and_while_executing_reject_job.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# :nocov: + +class UntilAndWhileExecutingRejectJob + include Sidekiq::Worker + + sidekiq_options lock: :until_and_while_executing, + queue: :working, + on_conflict: { + client: :reject, + server: :reject, + } + + def self.lock_args(args) + [args[0]] + end + + def perform(key); end +end diff --git a/spec/workers/until_and_while_executing_reject_job_spec.rb b/spec/workers/until_and_while_executing_reject_job_spec.rb new file mode 100644 index 00000000..3f9f2b1c --- /dev/null +++ b/spec/workers/until_and_while_executing_reject_job_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +RSpec.describe UntilAndWhileExecutingRejectJob do + it_behaves_like "sidekiq with options" do + let(:options) do + { + "queue" => :working, + "retry" => true, + "lock" => :until_and_while_executing, + "on_conflict" => { client: :reject, server: :reject }, + } + end + end + + it "rejects the job successfully" do + Sidekiq::Testing.disable! do + set = Sidekiq::ScheduledSet.new + + described_class.perform_at(Time.now + 30, 1) + expect(set.size).to eq(1) + + expect(described_class.perform_at(Time.now + 30, 1)).to be_nil + + set.each(&:delete) + end + end + + it "rejects job successfully when using perform_in" do + Sidekiq::Testing.disable! do + set = Sidekiq::ScheduledSet.new + + described_class.perform_in(30, 1) + expect(set.size).to eq(1) + + expect(described_class.perform_in(30, 1)).to be_nil + + set.each(&:delete) + end + end +end