hot_tub 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/HISTORY.md +6 -1
- data/README.md +110 -64
- data/benchmarks/block_passing.rb +96 -0
- data/benchmarks/hot_tub.rb +76 -41
- data/hot_tub.gemspec +2 -4
- data/lib/hot_tub/known_clients.rb +40 -23
- data/lib/hot_tub/pool.rb +96 -83
- data/lib/hot_tub/reaper.rb +14 -2
- data/lib/hot_tub/sessions.rb +111 -78
- data/lib/hot_tub/version.rb +1 -1
- data/lib/hot_tub.rb +48 -10
- data/spec/hot_tub/integration/excon_spec.rb +15 -21
- data/spec/hot_tub/integration/net_http_spec.rb +14 -14
- data/spec/hot_tub/integration/sessions_spec.rb +26 -15
- data/spec/hot_tub/pool_spec.rb +15 -34
- data/spec/hot_tub/sessions_spec.rb +50 -69
- data/spec/hot_tub_spec.rb +12 -7
- data/spec/spec_helper.rb +2 -0
- metadata +5 -19
data/lib/hot_tub.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'thread'
|
2
|
-
require 'thread_safe'
|
3
|
-
require 'logger'
|
4
2
|
require "hot_tub/version"
|
5
3
|
require "hot_tub/known_clients"
|
6
4
|
require "hot_tub/reaper"
|
@@ -8,7 +6,11 @@ require "hot_tub/pool"
|
|
8
6
|
require "hot_tub/sessions"
|
9
7
|
|
10
8
|
module HotTub
|
11
|
-
|
9
|
+
GLOBAL_SESSIONS = Sessions.new(:name => "Global Sessions")
|
10
|
+
|
11
|
+
@@logger = nil
|
12
|
+
@@trace = false
|
13
|
+
@@log_trace = false
|
12
14
|
|
13
15
|
def self.logger
|
14
16
|
@@logger
|
@@ -16,6 +18,25 @@ module HotTub
|
|
16
18
|
|
17
19
|
def self.logger=logger
|
18
20
|
@@logger = logger
|
21
|
+
set_log_trace
|
22
|
+
end
|
23
|
+
|
24
|
+
# Set to true for more detail logs
|
25
|
+
def self.trace=trace
|
26
|
+
@@trace = trace
|
27
|
+
set_log_trace
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.set_log_trace
|
31
|
+
@@log_trace = (!@@logger.nil? && @@trace)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.log_trace?
|
35
|
+
@@log_trace
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.sessions
|
39
|
+
GLOBAL_SESSIONS
|
19
40
|
end
|
20
41
|
|
21
42
|
def self.jruby?
|
@@ -26,12 +47,29 @@ module HotTub
|
|
26
47
|
(defined?(RUBY_ENGINE) and RUBY_ENGINE == 'rbx')
|
27
48
|
end
|
28
49
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
50
|
+
# Resets global sessions, useful in forked environments
|
51
|
+
# Does not reset one-off pools or one-off sessions
|
52
|
+
def self.reset!
|
53
|
+
GLOBAL_SESSIONS.reset!
|
54
|
+
end
|
55
|
+
|
56
|
+
# Shuts down global sessions, useful in forked environments
|
57
|
+
# Does not shutdown one-off pools or one-off sessions
|
58
|
+
def self.shutdown!
|
59
|
+
GLOBAL_SESSIONS.shutdown!
|
60
|
+
end
|
61
|
+
|
62
|
+
# Adds a new Pool to the global sessions
|
63
|
+
def self.add(url,opts={}, &client_block)
|
64
|
+
GLOBAL_SESSIONS.add(url, opts, &client_block)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.run(url ,&run_block)
|
68
|
+
pool = GLOBAL_SESSIONS.fetch(url)
|
69
|
+
pool.run &run_block
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.new(opts={}, &client_block)
|
73
|
+
Pool.new(opts,&client_block)
|
36
74
|
end
|
37
75
|
end
|
@@ -12,17 +12,17 @@ describe HotTub do
|
|
12
12
|
let(:threads) { [] }
|
13
13
|
|
14
14
|
before(:each) do
|
15
|
-
|
16
|
-
excon_thread_work(pool,
|
15
|
+
20.times do
|
16
|
+
excon_thread_work(pool, 10, threads)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it { expect(pool.current_size).to eql(4) }
|
20
|
+
it { expect(pool.current_size).to eql(4) }
|
21
21
|
|
22
22
|
it "should work" do
|
23
23
|
results = threads.collect{ |t| t[:status]}
|
24
|
-
expect(results.length).to eql(
|
25
|
-
expect(results.uniq).to eql([200])
|
24
|
+
expect(results.length).to eql(200)
|
25
|
+
expect(results.uniq).to eql([200])
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should shutdown" do
|
@@ -41,8 +41,8 @@ describe HotTub do
|
|
41
41
|
let(:threads) { [] }
|
42
42
|
|
43
43
|
before(:each) do
|
44
|
-
|
45
|
-
excon_thread_work(pool,
|
44
|
+
20.times do
|
45
|
+
excon_thread_work(pool, 10, threads)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -52,13 +52,13 @@ describe HotTub do
|
|
52
52
|
|
53
53
|
it "should reap" do
|
54
54
|
pool.reap!
|
55
|
-
expect(pool.current_size).to
|
55
|
+
expect(pool.current_size).to be <= 4
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should work" do
|
59
59
|
results = threads.collect{ |t| t[:status]}
|
60
|
-
expect(results.length).to eql(
|
61
|
-
expect(results.uniq).to eql([200])
|
60
|
+
expect(results.length).to eql(200)
|
61
|
+
expect(results.uniq).to eql([200])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -72,12 +72,12 @@ describe HotTub do
|
|
72
72
|
let(:threads) { [] }
|
73
73
|
|
74
74
|
before(:each) do
|
75
|
-
|
76
|
-
excon_thread_work(pool,
|
75
|
+
20.times do
|
76
|
+
excon_thread_work(pool, 10, threads)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
it { expect(pool.current_size).to be > 4 }
|
80
|
+
it { expect(pool.current_size).to be > 4 }
|
81
81
|
|
82
82
|
it "should reap" do
|
83
83
|
pool.reap!
|
@@ -86,8 +86,8 @@ describe HotTub do
|
|
86
86
|
|
87
87
|
it "should work" do
|
88
88
|
results = threads.collect{ |t| t[:status]}
|
89
|
-
expect(results.length).to eql(
|
90
|
-
expect(results.uniq).to eql([200])
|
89
|
+
expect(results.length).to eql(200)
|
90
|
+
expect(results.uniq).to eql([200])
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -99,13 +99,10 @@ describe HotTub do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should work" do
|
102
|
-
conn = nil
|
103
|
-
|
104
102
|
begin
|
105
103
|
th = Thread.new do
|
106
104
|
uri = URI.parse(HotTub::Server.slow_url)
|
107
105
|
pool.run do |connection|
|
108
|
-
conn = connection
|
109
106
|
connection.get(:path => uri.path).status
|
110
107
|
end
|
111
108
|
end
|
@@ -118,14 +115,11 @@ describe HotTub do
|
|
118
115
|
|
119
116
|
expect(pool.shutdown).to eql(true)
|
120
117
|
expect(pool.current_size).to eql(0)
|
121
|
-
expect(conn.send(:sockets)).to be_empty
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
121
|
end
|
126
122
|
|
127
|
-
|
128
|
-
|
129
123
|
def excon_thread_work(pool,thread_count=0, threads=[])
|
130
124
|
thread_count.times.each do
|
131
125
|
threads << Thread.new do
|
@@ -15,17 +15,17 @@ describe HotTub do
|
|
15
15
|
let(:threads) { [] }
|
16
16
|
|
17
17
|
before(:each) do
|
18
|
-
|
19
|
-
net_http_thread_work(pool,
|
18
|
+
20.times do
|
19
|
+
net_http_thread_work(pool, 10, threads)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
it { expect(pool.current_size).to eql(4) }
|
23
|
+
it { expect(pool.current_size).to eql(4) }
|
24
24
|
|
25
25
|
it "should work" do
|
26
26
|
results = threads.collect{ |t| t[:status]}
|
27
|
-
expect(results.length).to eql(
|
28
|
-
expect(results.uniq).to eql(['200'])
|
27
|
+
expect(results.length).to eql(200)
|
28
|
+
expect(results.uniq).to eql(['200'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should shutdown" do
|
@@ -48,8 +48,8 @@ describe HotTub do
|
|
48
48
|
let(:threads) { [] }
|
49
49
|
|
50
50
|
before(:each) do
|
51
|
-
|
52
|
-
net_http_thread_work(pool,
|
51
|
+
20.times do
|
52
|
+
net_http_thread_work(pool, 10, threads)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -57,8 +57,8 @@ describe HotTub do
|
|
57
57
|
it { expect(pool.current_size).to be <= 8 }
|
58
58
|
it "should work" do
|
59
59
|
results = threads.collect{ |t| t[:status]}
|
60
|
-
expect(results.length).to eql(
|
61
|
-
expect(results.uniq).to eql(['200'])
|
60
|
+
expect(results.length).to eql(200)
|
61
|
+
expect(results.uniq).to eql(['200'])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -76,17 +76,17 @@ describe HotTub do
|
|
76
76
|
let(:threads) { [] }
|
77
77
|
|
78
78
|
before(:each) do
|
79
|
-
|
80
|
-
net_http_thread_work(pool,
|
79
|
+
20.times do
|
80
|
+
net_http_thread_work(pool, 10, threads)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
it { expect(pool.current_size).to be > 4 }
|
84
|
+
it { expect(pool.current_size).to be > 4 }
|
85
85
|
|
86
86
|
it "should work" do
|
87
87
|
results = threads.collect{ |t| t[:status]}
|
88
|
-
expect(results.length).to eql(
|
89
|
-
expect(results.uniq).to eql(['200'])
|
88
|
+
expect(results.length).to eql(200)
|
89
|
+
expect(results.uniq).to eql(['200'])
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
@@ -4,23 +4,30 @@ describe HotTub, 'with sessions' do
|
|
4
4
|
|
5
5
|
let(:url) { HotTub::Server.url }
|
6
6
|
let(:url2) { HotTub::Server2.url }
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
|
9
|
+
let(:threads) { [] }
|
10
|
+
|
11
|
+
let(:sessions) { HotTub::Sessions.new(:name => "intText") }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
sessions.add(url) {
|
9
15
|
uri = URI.parse(url)
|
10
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
11
17
|
http.use_ssl = false
|
12
18
|
http.start
|
13
19
|
http
|
14
20
|
}
|
15
|
-
end
|
16
21
|
|
17
|
-
|
22
|
+
sessions.add(url2) {
|
23
|
+
Excon.new(url2)
|
24
|
+
}
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
|
27
|
+
5.times.each do
|
21
28
|
threads << Thread.new do
|
22
|
-
sessions.run(url)
|
23
|
-
sessions.run(url2) { |clnt| Thread.current[:
|
29
|
+
sessions.run(url) { |clnt| Thread.current[:result1] = clnt.get(URI.parse(url).path).code }
|
30
|
+
sessions.run(url2) { |clnt| Thread.current[:result2] = clnt.get(:path => URI.parse(url2).path).status }
|
24
31
|
end
|
25
32
|
end
|
26
33
|
threads.each do |t|
|
@@ -28,13 +35,17 @@ describe HotTub, 'with sessions' do
|
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
|
-
it "should
|
32
|
-
|
33
|
-
expect(results.length).to eql(10)
|
34
|
-
expect(results.uniq).to eql([results.first])
|
38
|
+
it "should create sessions" do
|
39
|
+
expect(sessions.instance_variable_get(:@_sessions).keys.length).to eql(2)
|
35
40
|
end
|
36
|
-
|
37
|
-
it "should work" do
|
38
|
-
|
41
|
+
|
42
|
+
it "should do work" do
|
43
|
+
results = threads.collect{ |t| t[:result1]}
|
44
|
+
expect(results.length).to eql(5)
|
45
|
+
expect(results.uniq).to eql([results.first])
|
46
|
+
results = threads.collect{ |t| t[:result2]}
|
47
|
+
expect(results.length).to eql(5)
|
48
|
+
expect(results.uniq).to eql([results.first])
|
39
49
|
end
|
50
|
+
|
40
51
|
end
|
data/spec/hot_tub/pool_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe HotTub::Pool do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have set the client" do
|
16
|
-
expect(pool.instance_variable_get(:@
|
16
|
+
expect(pool.instance_variable_get(:@client_block).call).to be_a(MocClient)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be true" do
|
@@ -61,11 +61,6 @@ describe HotTub::Pool do
|
|
61
61
|
expect(result).to_not be_nil
|
62
62
|
end
|
63
63
|
|
64
|
-
context 'block not given' do
|
65
|
-
it "should raise ArgumentError" do
|
66
|
-
expect { pool.run }.to raise_error(ArgumentError)
|
67
|
-
end
|
68
|
-
end
|
69
64
|
end
|
70
65
|
|
71
66
|
describe ':max_size option' do
|
@@ -123,8 +118,8 @@ describe HotTub::Pool do
|
|
123
118
|
let(:client) { MocClient.new }
|
124
119
|
|
125
120
|
before(:each) do
|
126
|
-
pool.instance_variable_set(:@_out, [
|
127
|
-
pool.instance_variable_set(:@_pool, [
|
121
|
+
pool.instance_variable_set(:@_out, [MocClient.new,MocClient.new])
|
122
|
+
pool.instance_variable_set(:@_pool, [client,MocClient.new,MocClient.new])
|
128
123
|
end
|
129
124
|
|
130
125
|
it "should reset pool" do
|
@@ -178,20 +173,7 @@ describe HotTub::Pool do
|
|
178
173
|
end
|
179
174
|
|
180
175
|
context 'private methods' do
|
181
|
-
let(:pool) { HotTub::Pool.new { MocClient.new} }
|
182
|
-
|
183
|
-
describe '#client' do
|
184
|
-
it "should raise HotTub::BlockingTimeout if an available is not found in time"do
|
185
|
-
pool.instance_variable_set(:@non_blocking,false)
|
186
|
-
pool.instance_variable_set(:@wait_timeout, 0.1)
|
187
|
-
allow(pool).to receive(:raise_alarm?).and_return(true)
|
188
|
-
expect { puts pool.send(:pop) }.to raise_error(HotTub::Pool::Timeout)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should return an instance of the client" do
|
192
|
-
expect(pool.send(:client)).to be_instance_of(MocClient)
|
193
|
-
end
|
194
|
-
end
|
176
|
+
let(:pool) { HotTub::Pool.new(:close => :close) { MocClient.new} }
|
195
177
|
|
196
178
|
describe '#pop' do
|
197
179
|
context "is allowed" do
|
@@ -211,10 +193,10 @@ describe HotTub::Pool do
|
|
211
193
|
end
|
212
194
|
context "client is not registered" do
|
213
195
|
it "should push client back to pool" do
|
214
|
-
clnt =
|
215
|
-
pool.instance_variable_get(:@_out).delete(clnt)
|
196
|
+
clnt = MocClient.new
|
216
197
|
pool.send(:push,clnt)
|
217
198
|
expect(pool.instance_variable_get(:@_pool).include?(clnt)).to eql(false)
|
199
|
+
expect(clnt).to be_closed
|
218
200
|
end
|
219
201
|
end
|
220
202
|
context "client is nil" do
|
@@ -230,17 +212,16 @@ describe HotTub::Pool do
|
|
230
212
|
it "should grow" do
|
231
213
|
pool = HotTub::Pool.new({:size => 4}) { MocClient.new }
|
232
214
|
failed = false
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
pool.run{|connection| connection.get }
|
238
|
-
end
|
239
|
-
end
|
240
|
-
threads.each do |t|
|
241
|
-
t.join
|
215
|
+
threads = []
|
216
|
+
20.times.each do
|
217
|
+
threads << Thread.new do
|
218
|
+
pool.run{|connection| connection.get }
|
242
219
|
end
|
243
|
-
|
220
|
+
end
|
221
|
+
sleep(0.01)
|
222
|
+
threads.each do |t|
|
223
|
+
t.join
|
224
|
+
end
|
244
225
|
expect(pool.current_size).to be >= 4
|
245
226
|
end
|
246
227
|
end
|
@@ -4,82 +4,60 @@ require 'uri'
|
|
4
4
|
require 'time'
|
5
5
|
describe HotTub::Sessions do
|
6
6
|
|
7
|
-
context 'initialized without a block' do
|
8
|
-
it "should raise error if block is not supplied" do
|
9
|
-
expect { HotTub::Sessions.new }.to raise_error(ArgumentError)
|
10
|
-
end
|
11
|
-
end
|
12
7
|
|
13
8
|
context 'initialized with a block' do
|
14
9
|
|
15
|
-
let(:
|
16
|
-
let(:uri) { URI(url) }
|
17
|
-
|
18
|
-
let(:sessions) { HotTub::Sessions.new { |url| MocClient.new(url) } }
|
10
|
+
let(:key) { "https://www.somewebsite.com" }
|
19
11
|
|
12
|
+
let(:sessions) { HotTub::Sessions.new }
|
20
13
|
|
21
|
-
describe '#
|
22
|
-
context
|
23
|
-
it "should
|
24
|
-
|
14
|
+
describe '#sessions' do
|
15
|
+
context 'HotTub::Pool as client' do
|
16
|
+
it "should add a new client for the key" do
|
17
|
+
sessions = HotTub::Sessions.new
|
18
|
+
sessions.add(key) { MocClient.new }
|
19
|
+
sns = sessions.instance_variable_get(:@_sessions)
|
20
|
+
expect(sns.size).to eql(1)
|
21
|
+
sns.each_value {|v| expect(v).to be_a( HotTub::Pool)}
|
25
22
|
end
|
26
23
|
end
|
24
|
+
end
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
expect(sessions.send(:to_key,uri)).to eql("#{uri.scheme}://#{uri.host}:#{uri.port}")
|
31
|
-
end
|
32
|
-
end
|
27
|
+
describe '#reaper' do
|
28
|
+
let(:url) { "https://www.somewebsite.com" }
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
30
|
+
let(:sessions) { HotTub::Sessions.new }
|
31
|
+
|
32
|
+
it "should start reaper after add" do
|
33
|
+
expect(sessions.reaper).to be_nil
|
34
|
+
sessions.add("https://www.somewebsite.com") { MocClient.new }
|
35
|
+
expect(sessions.reaper).to be_a(Thread)
|
42
36
|
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
expect(sessions.size).to eql(1)
|
51
|
-
sessions.each_value {|v| expect(v).to be_a( HotTub::Pool)}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
context "passed URL string" do
|
55
|
-
it "should set key with URI scheme-domain" do
|
56
|
-
sessions.sessions(url)
|
57
|
-
sns = sessions.instance_variable_get(:@sessions)
|
58
|
-
expect(sns["#{uri.scheme}://#{uri.host}:#{uri.port}"]).to be_a(HotTub::Pool)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
context "passed URI" do
|
62
|
-
it "should set key with URI scheme-domain" do
|
63
|
-
sessions.sessions(uri)
|
64
|
-
sns = sessions.instance_variable_get(:@sessions)
|
65
|
-
expect(sns["#{uri.scheme}://#{uri.host}:#{uri.port}"]).to be_a(HotTub::Pool)
|
66
|
-
end
|
67
|
-
end
|
38
|
+
it "should disable pool based reaper" do
|
39
|
+
sessions.add("https://www.somewebsite.com") { MocClient.new }
|
40
|
+
sessions.add("https://www.someOtherwebsite.com") { MocClient.new }
|
41
|
+
sessions.add("https://www.someOtherwebsiteToo.com") { MocClient.new }
|
42
|
+
session = sessions.instance_variable_get(:@_sessions)
|
43
|
+
session.each_value {|v| expect(v.reaper).to be_nil}
|
68
44
|
end
|
45
|
+
|
69
46
|
end
|
70
47
|
|
71
48
|
describe '#run' do
|
72
49
|
it "should pass run to pool" do
|
73
50
|
url = HotTub::Server.url
|
74
|
-
|
51
|
+
sessions = HotTub::Sessions.new
|
52
|
+
sessions.add(url) do
|
75
53
|
uri = URI.parse(url)
|
76
54
|
http = Net::HTTP.new(uri.host, uri.port)
|
77
55
|
http.use_ssl = false
|
78
56
|
http.start
|
79
57
|
http
|
80
|
-
|
58
|
+
end
|
81
59
|
result = nil
|
82
|
-
|
60
|
+
sessions.run(url) do |conn|
|
83
61
|
uri = URI.parse(url)
|
84
62
|
result = conn.get(uri.path).code
|
85
63
|
end
|
@@ -89,11 +67,11 @@ describe HotTub::Sessions do
|
|
89
67
|
|
90
68
|
describe '#clean!' do
|
91
69
|
it "should clean all pools in sessions" do
|
92
|
-
sessions = HotTub::Sessions.new
|
93
|
-
sessions.
|
94
|
-
sessions.
|
70
|
+
sessions = HotTub::Sessions.new
|
71
|
+
sessions.add('foo') { |url| MocClient.new(url) }
|
72
|
+
sessions.add('bar') { |url| MocClient.new(url) }
|
95
73
|
sessions.clean!
|
96
|
-
sessions.instance_variable_get(:@
|
74
|
+
sessions.instance_variable_get(:@_sessions).each_pair do |k,v|
|
97
75
|
v.instance_variable_get(:@_pool).each do |c|
|
98
76
|
expect(c).to be_cleaned
|
99
77
|
end
|
@@ -103,21 +81,21 @@ describe HotTub::Sessions do
|
|
103
81
|
|
104
82
|
describe '#drain!' do
|
105
83
|
it "should drain all pools in sessions" do
|
106
|
-
sessions = HotTub::Sessions.new
|
107
|
-
sessions.
|
108
|
-
sessions.
|
84
|
+
sessions = HotTub::Sessions.new
|
85
|
+
sessions.add('foo') { |url| MocClient.new(url) }
|
86
|
+
sessions.add('bar') { |url| MocClient.new(url) }
|
109
87
|
sessions.drain!
|
110
|
-
expect(sessions.instance_variable_get(:@
|
88
|
+
expect(sessions.instance_variable_get(:@_sessions)).to_not be_empty
|
111
89
|
end
|
112
90
|
end
|
113
91
|
|
114
92
|
describe '#reap!' do
|
115
93
|
it "should clean all pools in sessions" do
|
116
|
-
sessions = HotTub::Sessions.new
|
117
|
-
sessions.
|
118
|
-
sessions.
|
94
|
+
sessions = HotTub::Sessions.new
|
95
|
+
sessions.add('foo') { |url| MocClient.new(url) }
|
96
|
+
sessions.add('bar') { |url| MocClient.new(url) }
|
119
97
|
sessions.reap!
|
120
|
-
sessions.instance_variable_get(:@
|
98
|
+
sessions.instance_variable_get(:@_sessions).each_pair do |k,v|
|
121
99
|
v.instance_variable_get(:@_pool).each do |c|
|
122
100
|
expect(c).to be_reaped
|
123
101
|
end
|
@@ -127,11 +105,14 @@ describe HotTub::Sessions do
|
|
127
105
|
|
128
106
|
describe '#reset!' do
|
129
107
|
it "should reset all pools in sessions" do
|
130
|
-
sessions = HotTub::Sessions.new
|
131
|
-
sessions.
|
132
|
-
sessions.
|
108
|
+
sessions = HotTub::Sessions.new
|
109
|
+
sessions.add('foo') { |url| MocClient.new(url) }
|
110
|
+
sessions.add('bar') { |url| MocClient.new(url) }
|
133
111
|
sessions.reset!
|
134
|
-
|
112
|
+
sessions.instance_variable_get(:@_sessions).each_pair do |k,v|
|
113
|
+
expect(v.instance_variable_get(:@_pool)).to be_empty
|
114
|
+
expect(v.instance_variable_get(:@_out)).to be_empty
|
115
|
+
end
|
135
116
|
end
|
136
117
|
end
|
137
118
|
end
|
data/spec/hot_tub_spec.rb
CHANGED
@@ -3,17 +3,22 @@ describe HotTub do
|
|
3
3
|
|
4
4
|
context "helpers" do
|
5
5
|
describe '#new' do
|
6
|
-
|
7
6
|
it "should return a HotTub::Pool" do
|
8
7
|
expect(HotTub.new { |url| MocClient.new(url) }).to be_a(HotTub::Pool)
|
9
8
|
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#sessions' do
|
12
|
+
it {expect(HotTub.sessions).to be_a(HotTub::Sessions) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#add' do
|
16
|
+
it "should add a HotTub::Pool to Sessions" do
|
17
|
+
HotTub.add("http://test.com") { MocClient.new }
|
18
|
+
|
19
|
+
pool = HotTub.sessions.fetch("http://test.com")
|
10
20
|
|
11
|
-
|
12
|
-
it "should be a HotTub::Sessions with HotTub::Pool as client" do
|
13
|
-
session_with_pool = HotTub.new(:sessions => true) { |url| MocClient.new(url) }
|
14
|
-
pool = session_with_pool.sessions("http://test.com")
|
15
|
-
expect(pool).to be_a(HotTub::Pool)
|
16
|
-
end
|
21
|
+
expect(pool).to be_a(HotTub::Pool)
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,6 +17,8 @@ end
|
|
17
17
|
# in ./support/ and its subdirectories.
|
18
18
|
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
19
19
|
# HotTub.logger = Logger.new(STDOUT)
|
20
|
+
# HotTub.trace = true
|
21
|
+
|
20
22
|
RSpec.configure do |config|
|
21
23
|
config.before(:suite) do
|
22
24
|
HotTub::Server.run
|