mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
Allow to use custom token for lock
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.2.0
|
||||
- 2.3.1
|
||||
services:
|
||||
- memcached
|
||||
- redis-server
|
||||
|
||||
@@ -26,8 +26,8 @@ module Suo
|
||||
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
|
||||
@@ -95,8 +95,8 @@ module Suo
|
||||
|
||||
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
|
||||
|
||||
@@ -31,6 +31,12 @@ module ClientTests
|
||||
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?
|
||||
|
||||
Reference in New Issue
Block a user