healthy_pools 2.2.4 → 2.2.5.pre.0
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/.travis.yml +0 -1
- data/Changes.md +3 -3
- data/README.md +8 -8
- data/healthy_pools.gemspec +2 -2
- data/lib/{healthy_pool → healthy_pools}/monotonic_time.rb +1 -1
- data/lib/{healthy_pool → healthy_pools}/timed_stack.rb +5 -5
- data/lib/healthy_pools/version.rb +3 -0
- data/lib/{healthy_pool.rb → healthy_pools.rb} +7 -7
- data/test/helper.rb +1 -1
- data/test/{test_healthy_pool.rb → test_healthy_pools.rb} +42 -42
- data/test/{test_healthy_pool_timed_stack.rb → test_healthy_pools_timed_stack.rb} +8 -8
- metadata +9 -9
- data/lib/healthy_pool/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc5b62fabfb0fcae04081225b6afdd2d00f3077d
|
|
4
|
+
data.tar.gz: c715f486617b9374abf7bc68be2c5f3f275a2c33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 168ba9ee59196bef1d988efde340a290976a351b779aa5613c50ccc733b3cca8cb2971d79cd16140ab03919363bb81e3475a6c8fd0d14fe2b0fef5c7857db0ec
|
|
7
|
+
data.tar.gz: 801856731afe75064c61fc95b7181b3bd6383a4d57957bc3c301784f14181b80f32c68bcd4dd461b9b19138098f5fff562e16e6b3d55a8f9e9c6b23425d61b05
|
data/.travis.yml
CHANGED
data/Changes.md
CHANGED
|
@@ -98,7 +98,7 @@ end
|
|
|
98
98
|
- We now reuse objects when possible.
|
|
99
99
|
|
|
100
100
|
This means that under no contention, the same object will be checked
|
|
101
|
-
out from the pool after subsequent calls to `
|
|
101
|
+
out from the pool after subsequent calls to `HealthyPools#with`.
|
|
102
102
|
|
|
103
103
|
This change should have no impact on end user performance. If
|
|
104
104
|
anything, it should be an improvement, depending on what objects you
|
|
@@ -117,11 +117,11 @@ end
|
|
|
117
117
|
0.9.0
|
|
118
118
|
--------
|
|
119
119
|
|
|
120
|
-
- Move method\_missing magic into
|
|
120
|
+
- Move method\_missing magic into HealthyPools::Wrapper (djanowski)
|
|
121
121
|
- Remove BasicObject superclass (djanowski)
|
|
122
122
|
|
|
123
123
|
0.1.0
|
|
124
124
|
--------
|
|
125
125
|
|
|
126
126
|
- More precise timeouts and better error message
|
|
127
|
-
-
|
|
127
|
+
- HealthyPools now subclasses BasicObject so `method_missing` is more effective.
|
data/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Create a pool of objects to share amongst the fibers or threads in your Ruby
|
|
|
19
19
|
application:
|
|
20
20
|
|
|
21
21
|
``` ruby
|
|
22
|
-
$memcached =
|
|
22
|
+
$memcached = HealthyPools.new(size: 5, timeout: 5) { Dalli::Client.new }
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Then use the pool in your application:
|
|
@@ -46,15 +46,15 @@ This will only modify the resource-get timeout for this particular
|
|
|
46
46
|
invocation. This is useful if you want to fail-fast on certain non critical
|
|
47
47
|
sections when a resource is not available, or conversely if you are comfortable
|
|
48
48
|
blocking longer on a particular resource. This is not implemented in the below
|
|
49
|
-
`
|
|
49
|
+
`HealthyPools::Wrapper` class.
|
|
50
50
|
|
|
51
51
|
## Migrating to a Connection Pool
|
|
52
52
|
|
|
53
|
-
You can use `
|
|
53
|
+
You can use `HealthyPools::Wrapper` to wrap a single global connection,
|
|
54
54
|
making it easier to migrate existing connection code over time:
|
|
55
55
|
|
|
56
56
|
``` ruby
|
|
57
|
-
$redis =
|
|
57
|
+
$redis = HealthyPools::Wrapper.new(size: 5, timeout: 3) { Redis.connect }
|
|
58
58
|
$redis.sadd('foo', 1)
|
|
59
59
|
$redis.smembers('foo')
|
|
60
60
|
```
|
|
@@ -72,17 +72,17 @@ end
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
Once you've ported your entire system to use `with`, you can simply remove
|
|
75
|
-
`Wrapper` and use the simpler and faster `
|
|
75
|
+
`Wrapper` and use the simpler and faster `HealthyPools`.
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
## Shutdown
|
|
79
79
|
|
|
80
|
-
You can shut down a
|
|
80
|
+
You can shut down a HealthyPools instance once it should no longer be used.
|
|
81
81
|
Further checkout attempts will immediately raise an error but existing checkouts
|
|
82
82
|
will work.
|
|
83
83
|
|
|
84
84
|
```ruby
|
|
85
|
-
cp =
|
|
85
|
+
cp = HealthyPools.new { Redis.new }
|
|
86
86
|
cp.shutdown { |conn| conn.quit }
|
|
87
87
|
```
|
|
88
88
|
|
|
@@ -99,7 +99,7 @@ from the pool and a new one is created.
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
```ruby
|
|
102
|
-
cp =
|
|
102
|
+
cp = HealthyPools.new(health_check: lambda {|conn| conn.exec('select 1')}) { PG.connect }
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
|
data/healthy_pools.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
require "./lib/
|
|
2
|
+
require "./lib/healthy_pools/version"
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "healthy_pools"
|
|
6
|
-
s.version =
|
|
6
|
+
s.version = HealthyPools::VERSION
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
|
8
8
|
s.authors = ["Marco Montagna"]
|
|
9
9
|
s.email = ["marcojoemontagna@gmail.com"]
|
|
@@ -6,7 +6,7 @@ require_relative 'monotonic_time'
|
|
|
6
6
|
# Raised when you attempt to retrieve a connection from a pool that has been
|
|
7
7
|
# shut down.
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class HealthyPools::PoolShuttingDownError < RuntimeError; end
|
|
10
10
|
|
|
11
11
|
##
|
|
12
12
|
# The TimedStack manages a pool of homogeneous connections (or any resource
|
|
@@ -27,7 +27,7 @@ class HealthyPool::PoolShuttingDownError < RuntimeError; end
|
|
|
27
27
|
# ts.pop timeout: 5
|
|
28
28
|
# #=> raises Timeout::Error after 5 seconds
|
|
29
29
|
|
|
30
|
-
class
|
|
30
|
+
class HealthyPools::TimedStack
|
|
31
31
|
attr_reader :max
|
|
32
32
|
|
|
33
33
|
##
|
|
@@ -89,10 +89,10 @@ class HealthyPool::TimedStack
|
|
|
89
89
|
options, timeout = timeout, 0.5 if Hash === timeout
|
|
90
90
|
timeout = options.fetch :timeout, timeout
|
|
91
91
|
|
|
92
|
-
deadline =
|
|
92
|
+
deadline = HealthyPools.monotonic_time + timeout
|
|
93
93
|
@mutex.synchronize do
|
|
94
94
|
loop do
|
|
95
|
-
raise
|
|
95
|
+
raise HealthyPools::PoolShuttingDownError if @shutdown_block
|
|
96
96
|
while connection_stored?(options)
|
|
97
97
|
conn = fetch_connection(options)
|
|
98
98
|
begin
|
|
@@ -108,7 +108,7 @@ class HealthyPool::TimedStack
|
|
|
108
108
|
connection = try_create(options)
|
|
109
109
|
return connection if connection
|
|
110
110
|
|
|
111
|
-
to_wait = deadline -
|
|
111
|
+
to_wait = deadline - HealthyPools.monotonic_time
|
|
112
112
|
raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0
|
|
113
113
|
@resource.wait(@mutex, to_wait)
|
|
114
114
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require_relative '
|
|
2
|
-
require_relative '
|
|
1
|
+
require_relative 'healthy_pools/version'
|
|
2
|
+
require_relative 'healthy_pools/timed_stack'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
# Generic connection pool class for e.g. sharing a limited number of network connections
|
|
@@ -7,7 +7,7 @@ require_relative 'healthy_pool/timed_stack'
|
|
|
7
7
|
#
|
|
8
8
|
# Example usage with block (faster):
|
|
9
9
|
#
|
|
10
|
-
# @pool =
|
|
10
|
+
# @pool = HealthyPools.new { Redis.new }
|
|
11
11
|
#
|
|
12
12
|
# @pool.with do |redis|
|
|
13
13
|
# redis.lpop('my-list') if redis.llen('my-list') > 0
|
|
@@ -21,7 +21,7 @@ require_relative 'healthy_pool/timed_stack'
|
|
|
21
21
|
#
|
|
22
22
|
# Example usage replacing an existing connection (slower):
|
|
23
23
|
#
|
|
24
|
-
# $redis =
|
|
24
|
+
# $redis = HealthyPools.wrap { Redis.new }
|
|
25
25
|
#
|
|
26
26
|
# def do_work
|
|
27
27
|
# $redis.lpop('my-list') if $redis.llen('my-list') > 0
|
|
@@ -31,7 +31,7 @@ require_relative 'healthy_pool/timed_stack'
|
|
|
31
31
|
# - :size - number of connections to pool, defaults to 5
|
|
32
32
|
# - :timeout - amount of time to wait for a connection if none currently available, defaults to 5 seconds
|
|
33
33
|
#
|
|
34
|
-
class
|
|
34
|
+
class HealthyPools
|
|
35
35
|
DEFAULTS = {size: 5, timeout: 5, health_check: nil}
|
|
36
36
|
|
|
37
37
|
class Error < RuntimeError
|
|
@@ -104,7 +104,7 @@ end
|
|
|
104
104
|
::Thread.current[@key_count]-= 1
|
|
105
105
|
end
|
|
106
106
|
else
|
|
107
|
-
raise
|
|
107
|
+
raise HealthyPools::Error, 'no connections are checked out'
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
nil
|
|
@@ -130,7 +130,7 @@ end
|
|
|
130
130
|
METHODS = [:with, :pool_shutdown]
|
|
131
131
|
|
|
132
132
|
def initialize(options = {}, &block)
|
|
133
|
-
@pool = options.fetch(:pool) { ::
|
|
133
|
+
@pool = options.fetch(:pool) { ::HealthyPools.new(options, &block) }
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
def with(&block)
|
data/test/helper.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class TestHealthyPools < Minitest::Test
|
|
4
4
|
|
|
5
5
|
class NetworkConnection
|
|
6
6
|
SLEEP_TIME = 0.1
|
|
@@ -61,7 +61,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
61
61
|
|
|
62
62
|
def test_basic_multithreaded_usage
|
|
63
63
|
pool_size = 5
|
|
64
|
-
pool =
|
|
64
|
+
pool = HealthyPools.new(size: pool_size) { NetworkConnection.new }
|
|
65
65
|
|
|
66
66
|
start = Time.new
|
|
67
67
|
|
|
@@ -83,7 +83,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def test_timeout
|
|
86
|
-
pool =
|
|
86
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { NetworkConnection.new }
|
|
87
87
|
thread = Thread.new do
|
|
88
88
|
pool.with do |net|
|
|
89
89
|
net.do_something
|
|
@@ -105,7 +105,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
def test_with
|
|
108
|
-
pool =
|
|
108
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
109
109
|
|
|
110
110
|
pool.with do
|
|
111
111
|
assert_raises Timeout::Error do
|
|
@@ -117,7 +117,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def test_with_timeout
|
|
120
|
-
pool =
|
|
120
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
121
121
|
|
|
122
122
|
assert_raises Timeout::Error do
|
|
123
123
|
Timeout.timeout(0.01) do
|
|
@@ -133,7 +133,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
133
133
|
def test_checkout_ignores_timeout
|
|
134
134
|
skip("Thread.handle_interrupt not available") unless Thread.respond_to?(:handle_interrupt)
|
|
135
135
|
|
|
136
|
-
pool =
|
|
136
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
137
137
|
def pool.checkout(options)
|
|
138
138
|
sleep 0.015
|
|
139
139
|
super
|
|
@@ -157,7 +157,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
def test_explicit_return
|
|
160
|
-
pool =
|
|
160
|
+
pool = HealthyPools.new(timeout: 0, size: 1) do
|
|
161
161
|
mock = Minitest::Mock.new
|
|
162
162
|
def mock.disconnect!
|
|
163
163
|
raise "should not disconnect upon explicit return"
|
|
@@ -171,7 +171,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
def test_with_timeout_override
|
|
174
|
-
pool =
|
|
174
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { NetworkConnection.new }
|
|
175
175
|
|
|
176
176
|
t = Thread.new do
|
|
177
177
|
pool.with do |net|
|
|
@@ -192,7 +192,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
def test_checkin
|
|
195
|
-
pool =
|
|
195
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { NetworkConnection.new }
|
|
196
196
|
conn = pool.checkout
|
|
197
197
|
|
|
198
198
|
assert_raises Timeout::Error do
|
|
@@ -205,14 +205,14 @@ class TestHealthyPool < Minitest::Test
|
|
|
205
205
|
end
|
|
206
206
|
|
|
207
207
|
def test_returns_value
|
|
208
|
-
pool =
|
|
208
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
209
209
|
assert_equal 1, pool.with {|o| 1 }
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
def test_checkin_never_checkout
|
|
213
|
-
pool =
|
|
213
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
214
214
|
|
|
215
|
-
e = assert_raises
|
|
215
|
+
e = assert_raises HealthyPools::Error do
|
|
216
216
|
pool.checkin
|
|
217
217
|
end
|
|
218
218
|
|
|
@@ -220,18 +220,18 @@ class TestHealthyPool < Minitest::Test
|
|
|
220
220
|
end
|
|
221
221
|
|
|
222
222
|
def test_checkin_no_current_checkout
|
|
223
|
-
pool =
|
|
223
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
224
224
|
|
|
225
225
|
pool.checkout
|
|
226
226
|
pool.checkin
|
|
227
227
|
|
|
228
|
-
assert_raises
|
|
228
|
+
assert_raises HealthyPools::Error do
|
|
229
229
|
pool.checkin
|
|
230
230
|
end
|
|
231
231
|
end
|
|
232
232
|
|
|
233
233
|
def test_checkin_twice
|
|
234
|
-
pool =
|
|
234
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { Object.new }
|
|
235
235
|
|
|
236
236
|
pool.checkout
|
|
237
237
|
pool.checkout
|
|
@@ -250,7 +250,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
def test_checkout
|
|
253
|
-
pool =
|
|
253
|
+
pool = HealthyPools.new(size: 1) { NetworkConnection.new }
|
|
254
254
|
|
|
255
255
|
conn = pool.checkout
|
|
256
256
|
|
|
@@ -260,7 +260,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
def test_checkout_multithread
|
|
263
|
-
pool =
|
|
263
|
+
pool = HealthyPools.new(size: 2) { NetworkConnection.new }
|
|
264
264
|
conn = pool.checkout
|
|
265
265
|
|
|
266
266
|
t = Thread.new do
|
|
@@ -271,7 +271,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
def test_checkout_timeout
|
|
274
|
-
pool =
|
|
274
|
+
pool = HealthyPools.new(timeout: 0, size: 0) { Object.new }
|
|
275
275
|
|
|
276
276
|
assert_raises Timeout::Error do
|
|
277
277
|
pool.checkout
|
|
@@ -279,7 +279,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
279
279
|
end
|
|
280
280
|
|
|
281
281
|
def test_checkout_timeout_override
|
|
282
|
-
pool =
|
|
282
|
+
pool = HealthyPools.new(timeout: 0, size: 1) { NetworkConnection.new }
|
|
283
283
|
|
|
284
284
|
thread = Thread.new do
|
|
285
285
|
pool.with do |net|
|
|
@@ -298,7 +298,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
298
298
|
end
|
|
299
299
|
|
|
300
300
|
def test_passthru
|
|
301
|
-
pool =
|
|
301
|
+
pool = HealthyPools.wrap(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
|
|
302
302
|
assert_equal 1, pool.do_something
|
|
303
303
|
assert_equal 2, pool.do_something
|
|
304
304
|
assert_equal 5, pool.do_something_with_block { 3 }
|
|
@@ -306,7 +306,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
306
306
|
end
|
|
307
307
|
|
|
308
308
|
def test_passthru_respond_to
|
|
309
|
-
pool =
|
|
309
|
+
pool = HealthyPools.wrap(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
|
|
310
310
|
assert pool.respond_to?(:with)
|
|
311
311
|
assert pool.respond_to?(:do_something)
|
|
312
312
|
assert pool.respond_to?(:do_magic)
|
|
@@ -314,7 +314,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
314
314
|
end
|
|
315
315
|
|
|
316
316
|
def test_return_value
|
|
317
|
-
pool =
|
|
317
|
+
pool = HealthyPools.new(timeout: 2 * NetworkConnection::SLEEP_TIME, size: 1) { NetworkConnection.new }
|
|
318
318
|
result = pool.with do |net|
|
|
319
319
|
net.fast
|
|
320
320
|
end
|
|
@@ -322,7 +322,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
322
322
|
end
|
|
323
323
|
|
|
324
324
|
def test_heavy_threading
|
|
325
|
-
pool =
|
|
325
|
+
pool = HealthyPools.new(timeout: 0.5, size: 3) { NetworkConnection.new }
|
|
326
326
|
|
|
327
327
|
threads = Array.new(20) do
|
|
328
328
|
Thread.new do
|
|
@@ -336,7 +336,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
336
336
|
end
|
|
337
337
|
|
|
338
338
|
def test_reuses_objects_when_pool_not_saturated
|
|
339
|
-
pool =
|
|
339
|
+
pool = HealthyPools.new(size: 5) { NetworkConnection.new }
|
|
340
340
|
|
|
341
341
|
ids = 10.times.map do
|
|
342
342
|
pool.with { |c| c.object_id }
|
|
@@ -346,7 +346,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
346
346
|
end
|
|
347
347
|
|
|
348
348
|
def test_failed_health_check_removes_failed_connections
|
|
349
|
-
pool =
|
|
349
|
+
pool = HealthyPools.new(size: 5, health_check: lambda {|x| false}) { NetworkConnection.new }
|
|
350
350
|
|
|
351
351
|
ids = 10.times.map do
|
|
352
352
|
pool.with { |c| c.object_id }
|
|
@@ -356,7 +356,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
356
356
|
end
|
|
357
357
|
|
|
358
358
|
def test_exceptions_during_health_check_removes_connections
|
|
359
|
-
pool =
|
|
359
|
+
pool = HealthyPools.new(size: 5, health_check: lambda {|x| raise "failed"}) { NetworkConnection.new }
|
|
360
360
|
|
|
361
361
|
ids = 10.times.map do
|
|
362
362
|
pool.with { |c| c.object_id }
|
|
@@ -366,7 +366,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
366
366
|
end
|
|
367
367
|
|
|
368
368
|
def test_failed_health_check_does_not_remove_good_connections
|
|
369
|
-
pool =
|
|
369
|
+
pool = HealthyPools.new(size: 5, health_check: lambda {|x| true}) { NetworkConnection.new }
|
|
370
370
|
|
|
371
371
|
ids = 10.times.map do
|
|
372
372
|
pool.with { |c| c.object_id }
|
|
@@ -377,7 +377,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
377
377
|
|
|
378
378
|
def test_nested_checkout
|
|
379
379
|
recorder = Recorder.new
|
|
380
|
-
pool =
|
|
380
|
+
pool = HealthyPools.new(size: 1) { recorder }
|
|
381
381
|
pool.with do |r_outer|
|
|
382
382
|
@other = Thread.new do |t|
|
|
383
383
|
pool.with do |r_other|
|
|
@@ -402,7 +402,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
402
402
|
def test_shutdown_is_executed_for_all_connections
|
|
403
403
|
recorders = []
|
|
404
404
|
|
|
405
|
-
pool =
|
|
405
|
+
pool = HealthyPools.new(size: 3) do
|
|
406
406
|
Recorder.new.tap { |r| recorders << r }
|
|
407
407
|
end
|
|
408
408
|
|
|
@@ -418,11 +418,11 @@ class TestHealthyPool < Minitest::Test
|
|
|
418
418
|
end
|
|
419
419
|
|
|
420
420
|
def test_raises_error_after_shutting_down
|
|
421
|
-
pool =
|
|
421
|
+
pool = HealthyPools.new(size: 1) { true }
|
|
422
422
|
|
|
423
423
|
pool.shutdown { }
|
|
424
424
|
|
|
425
|
-
assert_raises
|
|
425
|
+
assert_raises HealthyPools::PoolShuttingDownError do
|
|
426
426
|
pool.checkout
|
|
427
427
|
end
|
|
428
428
|
end
|
|
@@ -430,7 +430,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
430
430
|
def test_runs_shutdown_block_asynchronously_if_connection_was_in_use
|
|
431
431
|
recorders = []
|
|
432
432
|
|
|
433
|
-
pool =
|
|
433
|
+
pool = HealthyPools.new(size: 3) do
|
|
434
434
|
Recorder.new.tap { |r| recorders << r }
|
|
435
435
|
end
|
|
436
436
|
|
|
@@ -452,7 +452,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
452
452
|
end
|
|
453
453
|
|
|
454
454
|
def test_raises_an_error_if_shutdown_is_called_without_a_block
|
|
455
|
-
pool =
|
|
455
|
+
pool = HealthyPools.new(size: 1) { }
|
|
456
456
|
|
|
457
457
|
assert_raises ArgumentError do
|
|
458
458
|
pool.shutdown
|
|
@@ -462,7 +462,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
462
462
|
def test_shutdown_is_executed_for_all_connections_in_wrapped_pool
|
|
463
463
|
recorders = []
|
|
464
464
|
|
|
465
|
-
wrapper =
|
|
465
|
+
wrapper = HealthyPools::Wrapper.new(size: 3) do
|
|
466
466
|
Recorder.new.tap { |r| recorders << r }
|
|
467
467
|
end
|
|
468
468
|
|
|
@@ -478,13 +478,13 @@ class TestHealthyPool < Minitest::Test
|
|
|
478
478
|
end
|
|
479
479
|
|
|
480
480
|
def test_wrapper_method_missing
|
|
481
|
-
wrapper =
|
|
481
|
+
wrapper = HealthyPools::Wrapper.new { NetworkConnection.new }
|
|
482
482
|
|
|
483
483
|
assert_equal 1, wrapper.fast
|
|
484
484
|
end
|
|
485
485
|
|
|
486
486
|
def test_wrapper_respond_to_eh
|
|
487
|
-
wrapper =
|
|
487
|
+
wrapper = HealthyPools::Wrapper.new { NetworkConnection.new }
|
|
488
488
|
|
|
489
489
|
assert_respond_to wrapper, :with
|
|
490
490
|
|
|
@@ -493,7 +493,7 @@ class TestHealthyPool < Minitest::Test
|
|
|
493
493
|
end
|
|
494
494
|
|
|
495
495
|
def test_wrapper_with
|
|
496
|
-
wrapper =
|
|
496
|
+
wrapper = HealthyPools::Wrapper.new(timeout: 0, size: 1) { Object.new }
|
|
497
497
|
|
|
498
498
|
wrapper.with do
|
|
499
499
|
assert_raises Timeout::Error do
|
|
@@ -513,15 +513,15 @@ class TestHealthyPool < Minitest::Test
|
|
|
513
513
|
end
|
|
514
514
|
|
|
515
515
|
def test_wrapper_kernel_methods
|
|
516
|
-
wrapper =
|
|
516
|
+
wrapper = HealthyPools::Wrapper.new(timeout: 0, size: 1) { ConnWithEval.new }
|
|
517
517
|
|
|
518
518
|
assert_equal "eval'ed 1", wrapper.eval(1)
|
|
519
519
|
end
|
|
520
520
|
|
|
521
521
|
def test_wrapper_with_connection_pool
|
|
522
522
|
recorder = Recorder.new
|
|
523
|
-
pool =
|
|
524
|
-
wrapper =
|
|
523
|
+
pool = HealthyPools.new(size: 1) { recorder }
|
|
524
|
+
wrapper = HealthyPools::Wrapper.new(pool: pool)
|
|
525
525
|
|
|
526
526
|
pool.with { |r| r.do_work('with') }
|
|
527
527
|
wrapper.do_work('wrapped')
|
|
@@ -530,14 +530,14 @@ class TestHealthyPool < Minitest::Test
|
|
|
530
530
|
end
|
|
531
531
|
|
|
532
532
|
def test_stats_without_active_connection
|
|
533
|
-
pool =
|
|
533
|
+
pool = HealthyPools.new(size: 2) { NetworkConnection.new }
|
|
534
534
|
|
|
535
535
|
assert_equal(2, pool.size)
|
|
536
536
|
assert_equal(2, pool.available)
|
|
537
537
|
end
|
|
538
538
|
|
|
539
539
|
def test_stats_with_active_connection
|
|
540
|
-
pool =
|
|
540
|
+
pool = HealthyPools.new(size: 2) { NetworkConnection.new }
|
|
541
541
|
|
|
542
542
|
pool.with do
|
|
543
543
|
assert_equal(1, pool.available)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class TestHealthyPoolsTimedStack < Minitest::Test
|
|
4
4
|
|
|
5
5
|
def setup
|
|
6
|
-
@stack =
|
|
6
|
+
@stack = HealthyPools::TimedStack.new { Object.new }
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def test_empty_eh
|
|
10
|
-
stack =
|
|
10
|
+
stack = HealthyPools::TimedStack.new(1) { Object.new }
|
|
11
11
|
|
|
12
12
|
refute_empty stack
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ class TestHealthyPoolTimedStack < Minitest::Test
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_length
|
|
24
|
-
stack =
|
|
24
|
+
stack = HealthyPools::TimedStack.new(1) { Object.new }
|
|
25
25
|
|
|
26
26
|
assert_equal 1, stack.length
|
|
27
27
|
|
|
@@ -35,7 +35,7 @@ class TestHealthyPoolTimedStack < Minitest::Test
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def test_object_creation_fails
|
|
38
|
-
stack =
|
|
38
|
+
stack = HealthyPools::TimedStack.new(2) { raise 'failure' }
|
|
39
39
|
|
|
40
40
|
begin
|
|
41
41
|
stack.pop
|
|
@@ -79,7 +79,7 @@ class TestHealthyPoolTimedStack < Minitest::Test
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def test_pop_full
|
|
82
|
-
stack =
|
|
82
|
+
stack = HealthyPools::TimedStack.new(1) { Object.new }
|
|
83
83
|
|
|
84
84
|
popped = stack.pop
|
|
85
85
|
|
|
@@ -104,13 +104,13 @@ class TestHealthyPoolTimedStack < Minitest::Test
|
|
|
104
104
|
def test_pop_shutdown
|
|
105
105
|
@stack.shutdown { }
|
|
106
106
|
|
|
107
|
-
assert_raises
|
|
107
|
+
assert_raises HealthyPools::PoolShuttingDownError do
|
|
108
108
|
@stack.pop
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def test_push
|
|
113
|
-
stack =
|
|
113
|
+
stack = HealthyPools::TimedStack.new(1) { Object.new }
|
|
114
114
|
|
|
115
115
|
conn = stack.pop
|
|
116
116
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: healthy_pools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.2.
|
|
4
|
+
version: 2.2.5.pre.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Montagna
|
|
@@ -67,13 +67,13 @@ files:
|
|
|
67
67
|
- README.md
|
|
68
68
|
- Rakefile
|
|
69
69
|
- healthy_pools.gemspec
|
|
70
|
-
- lib/
|
|
71
|
-
- lib/
|
|
72
|
-
- lib/
|
|
73
|
-
- lib/
|
|
70
|
+
- lib/healthy_pools.rb
|
|
71
|
+
- lib/healthy_pools/monotonic_time.rb
|
|
72
|
+
- lib/healthy_pools/timed_stack.rb
|
|
73
|
+
- lib/healthy_pools/version.rb
|
|
74
74
|
- test/helper.rb
|
|
75
|
-
- test/
|
|
76
|
-
- test/
|
|
75
|
+
- test/test_healthy_pools.rb
|
|
76
|
+
- test/test_healthy_pools_timed_stack.rb
|
|
77
77
|
homepage: https://github.com/mmontagna/healthy_pools
|
|
78
78
|
licenses:
|
|
79
79
|
- MIT
|
|
@@ -89,9 +89,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
89
89
|
version: '0'
|
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
requirements:
|
|
92
|
-
- - "
|
|
92
|
+
- - ">"
|
|
93
93
|
- !ruby/object:Gem::Version
|
|
94
|
-
version:
|
|
94
|
+
version: 1.3.1
|
|
95
95
|
requirements: []
|
|
96
96
|
rubyforge_project:
|
|
97
97
|
rubygems_version: 2.5.1
|
data/lib/healthy_pool/version.rb
DELETED