Skip to content

Commit

Permalink
Merge pull request #1 from Shuttlerock/master
Browse files Browse the repository at this point in the history
Allow to use custom token for lock
  • Loading branch information
nickelser authored Oct 6, 2016
2 parents a23282d + 05661e1 commit 2088fd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: ruby
rvm:
- 2.2.0
- 2.3.1
services:
- memcached
- redis-server
8 changes: 4 additions & 4 deletions lib/suo/client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def initialize(key, options = {})
super() # initialize Monitor mixin for thread safety
end

def lock
token = acquire_lock
def lock(custom_token = nil)
token = acquire_lock(custom_token)

if block_given? && token
begin
Expand Down Expand Up @@ -95,8 +95,8 @@ def clear

attr_accessor :retry_count

def acquire_lock
token = SecureRandom.base64(16)
def acquire_lock(token = nil)
token ||= SecureRandom.base64(16)

retry_with_timeout do
val, cas = get
Expand Down
6 changes: 6 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def test_single_resource_locking
assert_equal false, locked
end

def test_lock_with_custom_token
token = 'foo-bar'
lock = @client.lock token
assert_equal lock, token
end

def test_empty_lock_on_invalid_data
@client.send(:initial_set, "bad value")
assert_equal false, @client.locked?
Expand Down

0 comments on commit 2088fd9

Please sign in to comment.