4 Commits

Author SHA1 Message Date
Nick Elser
af1c476f08 Bump version. 2016-10-06 10:22:36 -07:00
Nick Elser
58fae54022 Minor style fixes. 2016-10-06 10:22:29 -07:00
Nick Elser
2088fd90b3 Merge pull request #1 from Shuttlerock/master
Allow to use custom token for lock
2016-10-06 10:20:35 -07:00
Vokhmin Alexey V
05661e143c Allow to use custom token for lock 2016-10-05 13:47:10 +03:00
6 changed files with 22 additions and 8 deletions

View File

@@ -74,7 +74,7 @@ Style/SpaceInsideBrackets:
Style/AndOr:
Enabled: false
Style/TrailingComma:
Style/TrailingCommaInLiteral:
Enabled: true
Style/SpaceBeforeComma:
@@ -98,7 +98,7 @@ Style/SpaceAfterColon:
Style/SpaceAfterComma:
Enabled: true
Style/SpaceAfterControlKeyword:
Style/SpaceAroundKeyword:
Enabled: true
Style/SpaceAfterNot:
@@ -163,7 +163,7 @@ Style/StringLiterals:
EnforcedStyle: double_quotes
Metrics/CyclomaticComplexity:
Max: 8
Max: 10
Metrics/LineLength:
Max: 128
@@ -214,3 +214,6 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Enabled: false
Style/Documentation:
Enabled: false

View File

@@ -1,6 +1,7 @@
language: ruby
rvm:
- 2.2.0
- 2.3.1
services:
- memcached
- redis-server

View File

@@ -1,3 +1,7 @@
## 0.3.2
- Custom lock tokens (thanks to avokhmin).
## 0.3.1
- Slight memory leak fix.

View File

@@ -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

View File

@@ -1,3 +1,3 @@
module Suo
VERSION = "0.3.1"
VERSION = "0.3.2".freeze
end

View File

@@ -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?