Skip to content

Commit

Permalink
Add spec for on_conflict reject
Browse files Browse the repository at this point in the history
  • Loading branch information
dsander committed Sep 26, 2021
1 parent 10359c2 commit 66fb5cc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/support/workers/until_and_while_executing_reject_job.rb
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions spec/workers/until_and_while_executing_reject_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 66fb5cc

Please sign in to comment.