Skip to content

Commit

Permalink
Increase number of lock "tries" by 1.
Browse files Browse the repository at this point in the history
So that "retry_count" actually means the number of retries.

Users that had set retry_count: 1 to disable retries at all will
need to set the parameter to 0 now.

Fixes #59.
  • Loading branch information
Malte Rohde committed Feb 27, 2018
1 parent 1e165c1 commit b34f07b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/redlock/client.rb
Expand Up @@ -149,7 +149,7 @@ def recover_from_script_flush
end

def try_lock_instances(resource, ttl, options)
tries = options[:extend] ? 1 : @retry_count
tries = options[:extend] ? 1 : (@retry_count + 1)

tries.times do |attempt_number|
# Wait a random delay before retrying.
Expand Down
6 changes: 3 additions & 3 deletions spec/client_spec.rb
Expand Up @@ -113,14 +113,14 @@
expect(lock_info).to eql(false)
end

it 'retries up to \'retry_count\' times' do
it 'tries up to \'retry_count\' + 1 times' do
expect(lock_manager).to receive(:lock_instances).exactly(
lock_manager_opts[:retry_count]).times.and_return(false)
lock_manager_opts[:retry_count] + 1).times.and_return(false)
lock_manager.lock(resource_key, ttl)
end

it 'sleeps in between retries' do
expect(lock_manager).to receive(:sleep).exactly(lock_manager_opts[:retry_count] - 1).times
expect(lock_manager).to receive(:sleep).exactly(lock_manager_opts[:retry_count]).times
lock_manager.lock(resource_key, ttl)
end

Expand Down

0 comments on commit b34f07b

Please sign in to comment.