Skip to content

Commit

Permalink
Allow locksmith delete to work with strings (#615)
Browse files Browse the repository at this point in the history
Previously if `call_script(:delete)` was returning a string an
error was raised since we couldn't call `.positive?` on it.

This change will ensure call script will always return a number.
  • Loading branch information
pinkahd authored Jun 29, 2021
1 parent 8c8d54c commit 2a588a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def delete
# Deletes the lock regardless of if it has a pttl set
#
def delete!
call_script(:delete, key.to_a, [job_id, config.pttl, config.type, config.limit]).positive?
call_script(:delete, key.to_a, [job_id, config.pttl, config.type, config.limit]).to_i.positive?
end

#
Expand Down
8 changes: 8 additions & 0 deletions spec/sidekiq_unique_jobs/locksmith_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
expect(locksmith_one).not_to be_locked
end

it "allows deletion when call script returns a string" do
locksmith_one.lock
allow(locksmith_one).to receive(:call_script).and_return("120")
locksmith_two.delete!

expect(locksmith_one).not_to be_locked
end

context "when lock_timeout is zero" do
let(:lock_timeout) { 0 }

Expand Down

0 comments on commit 2a588a6

Please sign in to comment.