|
|
@ -3,30 +3,32 @@
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
|
|
describe ConnectionPool::SharedTimedStack do
|
|
|
|
describe ConnectionPool::SharedTimedStack do
|
|
|
|
class MiniConnection
|
|
|
|
subject { described_class.new(5) { |site| mini_connection_class.new(site) } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let(:mini_connection_class) do
|
|
|
|
|
|
|
|
Class.new do
|
|
|
|
attr_reader :site
|
|
|
|
attr_reader :site
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(site)
|
|
|
|
def initialize(site)
|
|
|
|
@site = site
|
|
|
|
@site = site
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
subject { described_class.new(5) { |site| MiniConnection.new(site) } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe '#push' do
|
|
|
|
describe '#push' do
|
|
|
|
it 'keeps the connection in the stack' do
|
|
|
|
it 'keeps the connection in the stack' do
|
|
|
|
subject.push(MiniConnection.new('foo'))
|
|
|
|
subject.push(mini_connection_class.new('foo'))
|
|
|
|
expect(subject.size).to eq 1
|
|
|
|
expect(subject.size).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe '#pop' do
|
|
|
|
describe '#pop' do
|
|
|
|
it 'returns a connection' do
|
|
|
|
it 'returns a connection' do
|
|
|
|
expect(subject.pop('foo')).to be_a MiniConnection
|
|
|
|
expect(subject.pop('foo')).to be_a mini_connection_class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'returns the same connection that was pushed in' do
|
|
|
|
it 'returns the same connection that was pushed in' do
|
|
|
|
connection = MiniConnection.new('foo')
|
|
|
|
connection = mini_connection_class.new('foo')
|
|
|
|
subject.push(connection)
|
|
|
|
subject.push(connection)
|
|
|
|
expect(subject.pop('foo')).to be connection
|
|
|
|
expect(subject.pop('foo')).to be connection
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -36,8 +38,8 @@ describe ConnectionPool::SharedTimedStack do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'repurposes a connection for a different site when maximum amount is reached' do
|
|
|
|
it 'repurposes a connection for a different site when maximum amount is reached' do
|
|
|
|
5.times { subject.push(MiniConnection.new('foo')) }
|
|
|
|
5.times { subject.push(mini_connection_class.new('foo')) }
|
|
|
|
expect(subject.pop('bar')).to be_a MiniConnection
|
|
|
|
expect(subject.pop('bar')).to be_a mini_connection_class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -47,14 +49,14 @@ describe ConnectionPool::SharedTimedStack do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'returns false when there are connections on the stack' do
|
|
|
|
it 'returns false when there are connections on the stack' do
|
|
|
|
subject.push(MiniConnection.new('foo'))
|
|
|
|
subject.push(mini_connection_class.new('foo'))
|
|
|
|
expect(subject.empty?).to be false
|
|
|
|
expect(subject.empty?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe '#size' do
|
|
|
|
describe '#size' do
|
|
|
|
it 'returns the number of connections on the stack' do
|
|
|
|
it 'returns the number of connections on the stack' do
|
|
|
|
2.times { subject.push(MiniConnection.new('foo')) }
|
|
|
|
2.times { subject.push(mini_connection_class.new('foo')) }
|
|
|
|
expect(subject.size).to eq 2
|
|
|
|
expect(subject.size).to eq 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|