Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ rvm: | |
- 2.0.0-p648 | ||
- ruby-head | ||
- rbx-2 | ||
- jruby-head | ||
- jruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,107 @@ | ||
require 'spec_helper' | ||
|
||
|
||
describe HotTub do | ||
context "blocking (size equals max_size)" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4, :max_size => 4) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
unless HotTub.jruby? | ||
context "blocking (size equals max_size)" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4, :max_size => 4) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
|
||
let(:threads) { [] } | ||
let(:threads) { [] } | ||
|
||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
end | ||
end | ||
end | ||
|
||
it { expect(pool.current_size).to eql(4) } | ||
it { expect(pool.current_size).to eql(4) } | ||
|
||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
end | ||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
end | ||
|
||
it "should shutdown" do | ||
pool.shutdown! | ||
expect(pool.current_size).to eql(0) | ||
it "should shutdown" do | ||
pool.shutdown! | ||
expect(pool.current_size).to eql(0) | ||
end | ||
end | ||
end | ||
|
||
context "with larger max" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4, :max_size => 8) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
context "with larger max" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4, :max_size => 8) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
|
||
let(:threads) { [] } | ||
let(:threads) { [] } | ||
|
||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
end | ||
end | ||
end | ||
|
||
it { expect(pool.current_size).to be >= 4 } | ||
it { expect(pool.current_size).to be <= 8 } | ||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
it { expect(pool.current_size).to be >= 4 } | ||
it { expect(pool.current_size).to be <= 8 } | ||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
end | ||
end | ||
end | ||
|
||
context "sized without max" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
context "sized without max" do | ||
let(:pool) do | ||
HotTub::Pool.new(:size => 4) { | ||
uri = URI.parse(HotTub::Server.url) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = false | ||
http.start | ||
http | ||
} | ||
end | ||
|
||
let(:threads) { [] } | ||
let(:threads) { [] } | ||
|
||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
before(:each) do | ||
20.times do | ||
net_http_thread_work(pool, 10, threads) | ||
end | ||
end | ||
end | ||
|
||
it { expect(pool.current_size).to be > 4 } | ||
it { expect(pool.current_size).to be > 4 } | ||
|
||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
it "should work" do | ||
results = threads.collect{ |t| t[:status]} | ||
expect(results.length).to eql(200) | ||
expect(results.uniq).to eql(['200']) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def net_http_thread_work(pool,thread_count=0, threads=[]) | ||
thread_count.times.each do | ||
threads << Thread.new do | ||
uri = URI.parse(HotTub::Server.url) | ||
pool.run{|connection| Thread.current[:status] = connection.get(uri.path).code } | ||
def net_http_thread_work(pool,thread_count=0, threads=[]) | ||
thread_count.times.each do | ||
threads << Thread.new do | ||
uri = URI.parse(HotTub::Server.url) | ||
pool.run{|connection| Thread.current[:status] = connection.get(uri.path).code } | ||
end | ||
end | ||
threads.each do |t| | ||
t.join | ||
end | ||
end | ||
threads.each do |t| | ||
t.join | ||
end | ||
end |