connection_pool 2.2.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Changes.md +31 -2
- data/README.md +59 -31
- data/connection_pool.gemspec +15 -14
- data/lib/connection_pool/timed_stack.rb +19 -21
- data/lib/connection_pool/version.rb +1 -1
- data/lib/connection_pool/wrapper.rb +56 -0
- data/lib/connection_pool.rb +86 -77
- metadata +9 -20
- data/.gitignore +0 -4
- data/.travis.yml +0 -10
- data/Gemfile +0 -3
- data/Rakefile +0 -6
- data/lib/connection_pool/monotonic_time.rb +0 -66
- data/test/helper.rb +0 -8
- data/test/test_connection_pool.rb +0 -516
- data/test/test_connection_pool_timed_stack.rb +0 -149
@@ -1,149 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class TestConnectionPoolTimedStack < Minitest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@stack = ConnectionPool::TimedStack.new { Object.new }
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_empty_eh
|
10
|
-
stack = ConnectionPool::TimedStack.new(1) { Object.new }
|
11
|
-
|
12
|
-
refute_empty stack
|
13
|
-
|
14
|
-
popped = stack.pop
|
15
|
-
|
16
|
-
assert_empty stack
|
17
|
-
|
18
|
-
stack.push popped
|
19
|
-
|
20
|
-
refute_empty stack
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_length
|
24
|
-
stack = ConnectionPool::TimedStack.new(1) { Object.new }
|
25
|
-
|
26
|
-
assert_equal 1, stack.length
|
27
|
-
|
28
|
-
popped = stack.pop
|
29
|
-
|
30
|
-
assert_equal 0, stack.length
|
31
|
-
|
32
|
-
stack.push popped
|
33
|
-
|
34
|
-
assert_equal 1, stack.length
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_object_creation_fails
|
38
|
-
stack = ConnectionPool::TimedStack.new(2) { raise 'failure' }
|
39
|
-
|
40
|
-
begin
|
41
|
-
stack.pop
|
42
|
-
rescue => error
|
43
|
-
assert_equal 'failure', error.message
|
44
|
-
end
|
45
|
-
|
46
|
-
begin
|
47
|
-
stack.pop
|
48
|
-
rescue => error
|
49
|
-
assert_equal 'failure', error.message
|
50
|
-
end
|
51
|
-
|
52
|
-
refute_empty stack
|
53
|
-
assert_equal 2, stack.length
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_pop
|
57
|
-
object = Object.new
|
58
|
-
@stack.push object
|
59
|
-
|
60
|
-
popped = @stack.pop
|
61
|
-
|
62
|
-
assert_same object, popped
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_pop_empty
|
66
|
-
e = assert_raises Timeout::Error do
|
67
|
-
@stack.pop timeout: 0
|
68
|
-
end
|
69
|
-
|
70
|
-
assert_equal 'Waited 0 sec', e.message
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_pop_empty_2_0_compatibility
|
74
|
-
e = assert_raises Timeout::Error do
|
75
|
-
@stack.pop 0
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_equal 'Waited 0 sec', e.message
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_pop_full
|
82
|
-
stack = ConnectionPool::TimedStack.new(1) { Object.new }
|
83
|
-
|
84
|
-
popped = stack.pop
|
85
|
-
|
86
|
-
refute_nil popped
|
87
|
-
assert_empty stack
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_pop_wait
|
91
|
-
thread = Thread.start do
|
92
|
-
@stack.pop
|
93
|
-
end
|
94
|
-
|
95
|
-
Thread.pass while thread.status == 'run'
|
96
|
-
|
97
|
-
object = Object.new
|
98
|
-
|
99
|
-
@stack.push object
|
100
|
-
|
101
|
-
assert_same object, thread.value
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_pop_shutdown
|
105
|
-
@stack.shutdown { }
|
106
|
-
|
107
|
-
assert_raises ConnectionPool::PoolShuttingDownError do
|
108
|
-
@stack.pop
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_push
|
113
|
-
stack = ConnectionPool::TimedStack.new(1) { Object.new }
|
114
|
-
|
115
|
-
conn = stack.pop
|
116
|
-
|
117
|
-
stack.push conn
|
118
|
-
|
119
|
-
refute_empty stack
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_push_shutdown
|
123
|
-
called = []
|
124
|
-
|
125
|
-
@stack.shutdown do |object|
|
126
|
-
called << object
|
127
|
-
end
|
128
|
-
|
129
|
-
@stack.push Object.new
|
130
|
-
|
131
|
-
refute_empty called
|
132
|
-
assert_empty @stack
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_shutdown
|
136
|
-
@stack.push Object.new
|
137
|
-
|
138
|
-
called = []
|
139
|
-
|
140
|
-
@stack.shutdown do |object|
|
141
|
-
called << object
|
142
|
-
end
|
143
|
-
|
144
|
-
refute_empty called
|
145
|
-
assert_empty @stack
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|