Skip to content

Commit

Permalink
fix(locksmith): execute to yield without arguments (#710)
Browse files Browse the repository at this point in the history
Closes #683
  • Loading branch information
mhenrixon authored May 4, 2022
1 parent 5592318 commit d7702ba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def ==(other)
# @yieldparam [string] job_id the sidekiq JID
# @yieldreturn [void] whatever the calling block returns
def lock!(conn, primed_method, wait = nil)
return yield job_id if locked?(conn)
return yield if locked?(conn)

enqueue(conn) do |queued_jid|
reflect(:debug, :queued, item, queued_jid)
Expand All @@ -199,7 +199,7 @@ def lock!(conn, primed_method, wait = nil)

if locked_jid
reflect(:debug, :locked, item, locked_jid)
return yield job_id
return yield
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
end
end

it "yields without arguments" do
process_one.lock
process_one.execute {}
blk = -> {}

expect { process_one.execute(&blk) }.not_to raise_error
end

context "when worker raises error in runtime lock" do
before do
allow(runtime_one.locksmith).to receive(:execute).and_raise(RuntimeError, "Hell")
Expand Down
8 changes: 8 additions & 0 deletions spec/sidekiq_unique_jobs/lock/while_executing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
expect(callback_two).not_to have_received(:call)
end

it "yields without arguments" do
process_one.lock
process_one.execute {}
blk = -> {}

expect { process_one.execute(&blk) }.not_to raise_error
end

context "when no callback is defined" do
let(:job_class) { WhileExecutingRescheduleJob }
let(:callback_one) { -> { true } }
Expand Down
8 changes: 8 additions & 0 deletions spec/support/shared_examples/a_lockable_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,13 @@

expect(process_two).to have_received(:reflect).with(:execution_failed, item_two)
end

it "yields without arguments" do
process_one.lock
process_one.execute {}
blk = -> {}

expect { process_one.execute(&blk) }.not_to raise_error
end
end
end

0 comments on commit d7702ba

Please sign in to comment.