discourse/spec/components/freedom_patches/pool_drainer_spec.rb

48 lines
916 B
Ruby
Raw Normal View History

require 'spec_helper'
describe 'pool drainer' do
let(:pool) do
ActiveRecord::Base.connection_pool
end
it 'can correctly drain the connection pool' do
pool.drain
old = pool.connections.length
2015-01-10 00:34:37 +08:00
expect(old).to eq(1)
Thread.new do
conn = pool.checkout
pool.checkin conn
end.join
2015-01-10 00:34:37 +08:00
expect(pool.connections.length).to eq(old+1)
pool.drain
2015-01-10 00:34:37 +08:00
expect(pool.connections.length).to eq(old)
end
it 'can drain with idle time setting' do
pool.drain
old = pool.connections.length
2015-01-10 00:34:37 +08:00
expect(old).to eq(1)
Thread.new do
conn = pool.checkout
pool.checkin conn
end.join
2015-01-10 00:34:37 +08:00
expect(pool.connections.length).to eq(old+1)
pool.drain(1.minute)
2015-01-10 00:34:37 +08:00
expect(pool.connections.length).to eq(old+1)
# make sure we don't corrupt internal state
20.times do
conn = pool.checkout
pool.checkin conn
pool.drain
end
end
end