Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass lock timeout to primed_async #624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def execute(&block)
raise SidekiqUniqueJobs::InvalidArgument, "#execute needs a block" unless block

redis(redis_pool) do |conn|
lock!(conn, method(:primed_async), &block)
lock!(conn, method(:primed_async), config.timeout, &block)
end
end

Expand Down
19 changes: 19 additions & 0 deletions spec/sidekiq_unique_jobs/locksmith_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@
context "when lock_timeout is 1" do
let(:lock_timeout) { 1 }

let(:slow_brpoplpush) do
proc do
sleep(0.75)
locksmith_one.job_id
end
end

it "blocks other locks" do
did_we_get_in = false

Expand All @@ -299,6 +306,18 @@

expect(did_we_get_in).to be false
end

it "waits for brpoplpush when resolving the promise" do
allow(locksmith_one).to receive(:brpoplpush).with(anything, 1, &slow_brpoplpush)

did_we_get_in = false
locksmith_one.execute do
did_we_get_in = true
end

expect(locksmith_one).to have_received(:brpoplpush)
expect(did_we_get_in).to be true
end
end

# it "reflects" do
Expand Down