مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
45
spec/lib/postal/message_db/connection_pool_spec.rb
Normal file
45
spec/lib/postal/message_db/connection_pool_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Postal::MessageDB::ConnectionPool do
|
||||
|
||||
subject(:pool) { described_class.new }
|
||||
|
||||
describe '#use' do
|
||||
it 'yields a connection' do
|
||||
counter = 0
|
||||
pool.use do |connection|
|
||||
expect(connection).to be_a Mysql2::Client
|
||||
counter += 1
|
||||
end
|
||||
expect(counter).to eq 1
|
||||
end
|
||||
|
||||
it 'checks in a connection after the block has executed' do
|
||||
connection = nil
|
||||
pool.use do |c|
|
||||
expect(pool.connections).to be_empty
|
||||
connection = c
|
||||
end
|
||||
expect(pool.connections).to eq [connection]
|
||||
end
|
||||
|
||||
it 'checks in a connection if theres an error in the block' do
|
||||
expect do
|
||||
pool.use do |c|
|
||||
raise StandardError
|
||||
end
|
||||
end.to raise_error StandardError
|
||||
expect(pool.connections).to match [kind_of(Mysql2::Client)]
|
||||
end
|
||||
|
||||
it 'does not check in connections when there is a connection error' do
|
||||
expect do
|
||||
pool.use do
|
||||
raise Mysql2::Error, "lost connection to server"
|
||||
end
|
||||
end.to raise_error Mysql2::Error
|
||||
expect(pool.connections).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
المرجع في مشكلة جديدة
حظر مستخدم