suo 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/suo/client/base.rb +8 -9
- data/lib/suo/clients.rb +1 -1
- data/lib/suo/errors.rb +3 -0
- data/lib/suo/version.rb +1 -1
- data/suo.gemspec +2 -0
- data/test/client_test.rb +14 -8
- metadata +4 -4
- data/lib/suo/client/errors.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0688005f9b0d058a3aa50d0225cf15c52b74e036
|
4
|
+
data.tar.gz: 65a1be72254409473e51e7455a8e718db505c87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8f222bb46a28971467792d8b75c939d8e62869860a53dffa587e85cd2d9075211e229c670d14868730b714dcd2ac8db2e2a3b4666717238450a8f6022772f5
|
7
|
+
data.tar.gz: 0671a1a94f678a9da525c50b756fee60b3a8e207de45693bfe79deddf9d1cf333d0be0130e166c0c1ef4a088f9e6d95810bdd955fd6d5a0c7e83df20fe5b98ca
|
data/CHANGELOG.md
CHANGED
data/lib/suo/client/base.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Suo
|
2
2
|
module Client
|
3
3
|
class Base
|
4
|
+
|
4
5
|
DEFAULT_OPTIONS = {
|
5
6
|
retry_timeout: 0.1,
|
6
7
|
retry_delay: 0.01,
|
@@ -111,7 +112,7 @@ module Suo
|
|
111
112
|
break unless acquisition_lock
|
112
113
|
break if set(key, serialize_locks(locks), cas, options)
|
113
114
|
end
|
114
|
-
rescue
|
115
|
+
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
|
115
116
|
# ignore - assume success due to optimistic locking
|
116
117
|
end
|
117
118
|
|
@@ -124,8 +125,6 @@ module Suo
|
|
124
125
|
|
125
126
|
fail "Client required" unless options[:client]
|
126
127
|
|
127
|
-
options[:retry_count] = (options[:retry_timeout] / options[:retry_delay].to_f).ceil
|
128
|
-
|
129
128
|
options
|
130
129
|
end
|
131
130
|
|
@@ -148,13 +147,13 @@ module Suo
|
|
148
147
|
end
|
149
148
|
|
150
149
|
def retry_with_timeout(key, options)
|
150
|
+
count = (options[:retry_timeout] / options[:retry_delay].to_f).ceil
|
151
|
+
|
151
152
|
start = Time.now.to_f
|
152
153
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
break if now - start > options[:retry_timeout]
|
157
|
-
end
|
154
|
+
count.times do
|
155
|
+
now = Time.now.to_f
|
156
|
+
break if now - start > options[:retry_timeout]
|
158
157
|
|
159
158
|
synchronize(key, options) do
|
160
159
|
yield
|
@@ -163,7 +162,7 @@ module Suo
|
|
163
162
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
164
163
|
end
|
165
164
|
rescue => _
|
166
|
-
raise
|
165
|
+
raise LockClientError
|
167
166
|
end
|
168
167
|
|
169
168
|
def serialize_locks(locks)
|
data/lib/suo/clients.rb
CHANGED
data/lib/suo/errors.rb
ADDED
data/lib/suo/version.rb
CHANGED
data/suo.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.required_ruby_version = "~> 2.0"
|
24
|
+
|
23
25
|
spec.add_dependency "dalli"
|
24
26
|
spec.add_dependency "redis"
|
25
27
|
spec.add_dependency "msgpack"
|
data/test/client_test.rb
CHANGED
@@ -11,6 +11,12 @@ module ClientTests
|
|
11
11
|
assert_equal "Client required", exception.message
|
12
12
|
end
|
13
13
|
|
14
|
+
def test_throws_failed_error_on_bad_client
|
15
|
+
assert_raises(Suo::LockClientError) do
|
16
|
+
@klass.lock(TEST_KEY, 1, client: {})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
def test_class_single_resource_locking
|
15
21
|
lock1 = @klass.lock(TEST_KEY, 1, client: @klass_client)
|
16
22
|
refute_nil lock1
|
@@ -73,10 +79,10 @@ module ClientTests
|
|
73
79
|
success_counter = Queue.new
|
74
80
|
failure_counter = Queue.new
|
75
81
|
|
76
|
-
|
82
|
+
50.times.map do |i|
|
77
83
|
Thread.new do
|
78
|
-
success = @client.lock(TEST_KEY,
|
79
|
-
sleep(
|
84
|
+
success = @client.lock(TEST_KEY, 25, retry_timeout: 0.9) do
|
85
|
+
sleep(3)
|
80
86
|
success_counter << i
|
81
87
|
end
|
82
88
|
|
@@ -84,17 +90,17 @@ module ClientTests
|
|
84
90
|
end
|
85
91
|
end.map(&:join)
|
86
92
|
|
87
|
-
assert_equal
|
88
|
-
assert_equal
|
93
|
+
assert_equal 25, success_counter.size
|
94
|
+
assert_equal 25, failure_counter.size
|
89
95
|
end
|
90
96
|
|
91
97
|
def test_instance_multiple_resource_locking_longer_timeout
|
92
98
|
success_counter = Queue.new
|
93
99
|
failure_counter = Queue.new
|
94
100
|
|
95
|
-
|
101
|
+
50.times.map do |i|
|
96
102
|
Thread.new do
|
97
|
-
success = @client.lock(TEST_KEY,
|
103
|
+
success = @client.lock(TEST_KEY, 25, retry_timeout: 2) do
|
98
104
|
sleep(0.5)
|
99
105
|
success_counter << i
|
100
106
|
end
|
@@ -103,7 +109,7 @@ module ClientTests
|
|
103
109
|
end
|
104
110
|
end.map(&:join)
|
105
111
|
|
106
|
-
assert_equal
|
112
|
+
assert_equal 50, success_counter.size
|
107
113
|
assert_equal 0, failure_counter.size
|
108
114
|
end
|
109
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Elser
|
@@ -129,10 +129,10 @@ files:
|
|
129
129
|
- bin/setup
|
130
130
|
- lib/suo.rb
|
131
131
|
- lib/suo/client/base.rb
|
132
|
-
- lib/suo/client/errors.rb
|
133
132
|
- lib/suo/client/memcached.rb
|
134
133
|
- lib/suo/client/redis.rb
|
135
134
|
- lib/suo/clients.rb
|
135
|
+
- lib/suo/errors.rb
|
136
136
|
- lib/suo/version.rb
|
137
137
|
- suo.gemspec
|
138
138
|
- test/client_test.rb
|
@@ -147,9 +147,9 @@ require_paths:
|
|
147
147
|
- lib
|
148
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
152
|
+
version: '2.0'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|