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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6334c57e0648ae8fefdeb1113664c3e6631dd03c
4
- data.tar.gz: 0f35accaea812d463d911b1602a30372952ca19b
3
+ metadata.gz: 0688005f9b0d058a3aa50d0225cf15c52b74e036
4
+ data.tar.gz: 65a1be72254409473e51e7455a8e718db505c87a
5
5
  SHA512:
6
- metadata.gz: 51081aad925fa7032551ff81be52f724ed8fcd9592dfbfb7aea70d1a837597bdeabdcbe0bb9946629cbc2f853a81d1e8b501ec2b1d1ba8ba3c57a4ff6d43a77a
7
- data.tar.gz: cce84bf639f8303f241a3c901d92991ae5e72b95c918601db06b75ca98cef250c85d3a00c0a2e3412ce539f2eb6acfedfeda1297ae1fbf033844477bc26b79fa
6
+ metadata.gz: 8e8f222bb46a28971467792d8b75c939d8e62869860a53dffa587e85cd2d9075211e229c670d14868730b714dcd2ac8db2e2a3b4666717238450a8f6022772f5
7
+ data.tar.gz: 0671a1a94f678a9da525c50b756fee60b3a8e207de45693bfe79deddf9d1cf333d0be0130e166c0c1ef4a088f9e6d95810bdd955fd6d5a0c7e83df20fe5b98ca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.3
2
+
3
+ - Properly throw Suo::LockClientError when the connection itself fails (Memcache server not reachable, etc.)
4
+
1
5
  ## 0.1.2
2
6
 
3
7
  - Fix retry_timeout to properly use the full time (was being calculated incorrectly).
@@ -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 FailedToAcquireLock => _ # rubocop:disable Lint/HandleExceptions
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
- options[:retry_count].times do
154
- if options[:retry_timeout]
155
- now = Time.now.to_f
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 FailedToAcquireLock
165
+ raise LockClientError
167
166
  end
168
167
 
169
168
  def serialize_locks(locks)
data/lib/suo/clients.rb CHANGED
@@ -8,7 +8,7 @@ require "redis"
8
8
 
9
9
  require "msgpack"
10
10
 
11
- require "suo/client/errors"
11
+ require "suo/errors"
12
12
  require "suo/client/base"
13
13
  require "suo/client/memcached"
14
14
  require "suo/client/redis"
data/lib/suo/errors.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Suo
2
+ class LockClientError < StandardError; end
3
+ end
data/lib/suo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Suo
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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
- 100.times.map do |i|
82
+ 50.times.map do |i|
77
83
  Thread.new do
78
- success = @client.lock(TEST_KEY, 50, retry_timeout: 0.5) do
79
- sleep(2)
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 50, success_counter.size
88
- assert_equal 50, failure_counter.size
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
- 100.times.map do |i|
101
+ 50.times.map do |i|
96
102
  Thread.new do
97
- success = @client.lock(TEST_KEY, 50, retry_timeout: 2) do
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 100, success_counter.size
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.2
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
  - - ">="
@@ -1,7 +0,0 @@
1
- module Suo
2
- module Client
3
- module Errors
4
- class FailedToAcquireLock < StandardError; end
5
- end
6
- end
7
- end