gene_pool 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +4 -0
- data/lib/gene_pool.rb +1 -1
- data/test/gene_pool_test.rb +65 -0
- metadata +2 -2
data/History.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
GenePool Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
1.2.3 / 2012-02-23
|
5
|
+
|
6
|
+
- Allow setting of options[:close_proc] to nil (Should have just stayed home today).
|
7
|
+
|
4
8
|
1.2.2 / 2012-02-23
|
5
9
|
|
6
10
|
- Do a respond_to? to check compatibility instead of hacking around with $VERBOSE
|
data/lib/gene_pool.rb
CHANGED
@@ -23,7 +23,7 @@ class GenePool
|
|
23
23
|
@warn_timeout = options[:warn_timeout] || 5.0
|
24
24
|
@idle_timeout = options[:idle_timeout]
|
25
25
|
@logger = options[:logger]
|
26
|
-
@close_proc = options[:close_proc] || :close
|
26
|
+
@close_proc = options[:close_proc] || (!options.has_key?(:close_proc) && :close)
|
27
27
|
|
28
28
|
unless @logger
|
29
29
|
@logger = Logger.new(STDERR)
|
data/test/gene_pool_test.rb
CHANGED
@@ -17,6 +17,7 @@ class DummyConnection
|
|
17
17
|
sleep sleep_time if sleep_time
|
18
18
|
@count = count
|
19
19
|
@closed = false
|
20
|
+
@other_closed = false
|
20
21
|
end
|
21
22
|
|
22
23
|
def to_s
|
@@ -34,6 +35,14 @@ class DummyConnection
|
|
34
35
|
def closed?
|
35
36
|
@closed
|
36
37
|
end
|
38
|
+
|
39
|
+
def other_close
|
40
|
+
@other_closed = true
|
41
|
+
end
|
42
|
+
|
43
|
+
def other_closed?
|
44
|
+
@other_closed
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
|
@@ -338,4 +347,60 @@ class GenePoolTest < Test::Unit::TestCase
|
|
338
347
|
assert !conn3.closed?
|
339
348
|
end
|
340
349
|
end
|
350
|
+
|
351
|
+
context 'close_proc' do
|
352
|
+
should 'default to close if not specified' do
|
353
|
+
@gene_pool = GenePool.new do
|
354
|
+
DummyConnection.new(0, 0)
|
355
|
+
end
|
356
|
+
conn = nil
|
357
|
+
@gene_pool.with_connection { |c| conn = c }
|
358
|
+
@gene_pool.remove_idle(0)
|
359
|
+
assert conn.closed?
|
360
|
+
assert !conn.other_closed?
|
361
|
+
end
|
362
|
+
|
363
|
+
should 'allow symbol to execute a different method from close' do
|
364
|
+
@gene_pool = GenePool.new(:close_proc => :other_close) do
|
365
|
+
DummyConnection.new(0, 0)
|
366
|
+
end
|
367
|
+
conn = nil
|
368
|
+
@gene_pool.with_connection { |c| conn = c }
|
369
|
+
@gene_pool.remove_idle(0)
|
370
|
+
assert !conn.closed?
|
371
|
+
assert conn.other_closed?
|
372
|
+
end
|
373
|
+
|
374
|
+
|
375
|
+
should 'allow nil so it does not execute a close' do
|
376
|
+
@gene_pool = GenePool.new(:close_proc => nil) do
|
377
|
+
DummyConnection.new(0, 0)
|
378
|
+
end
|
379
|
+
conn = nil
|
380
|
+
@gene_pool.with_connection { |c| conn = c }
|
381
|
+
@gene_pool.remove_idle(0)
|
382
|
+
assert !conn.closed?
|
383
|
+
assert !conn.other_closed?
|
384
|
+
end
|
385
|
+
|
386
|
+
should 'allow proc that gets executed on close' do
|
387
|
+
foo = 1
|
388
|
+
close_conn = nil
|
389
|
+
my_close = lambda do |conn|
|
390
|
+
close_conn = conn
|
391
|
+
foo = 2
|
392
|
+
end
|
393
|
+
@gene_pool = GenePool.new(:close_proc => my_close) do
|
394
|
+
DummyConnection.new(0, 0)
|
395
|
+
end
|
396
|
+
conn = nil
|
397
|
+
@gene_pool.with_connection { |c| conn = c }
|
398
|
+
@gene_pool.remove_idle(0)
|
399
|
+
assert !conn.closed?
|
400
|
+
assert !conn.other_closed?
|
401
|
+
assert_same conn, close_conn
|
402
|
+
assert_equal 2, foo
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
341
406
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gene_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -39,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
segments:
|
41
41
|
- 0
|
42
|
-
hash: -
|
42
|
+
hash: -1970071979661874936
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|