1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-12-01 05:43:04 +00:00

fix: adds new connection pool which will discard failed clients

closes #2780
هذا الالتزام موجود في:
Adam Cooke
2024-02-06 11:53:53 +00:00
الأصل 304828a672
التزام 54306a9748
5 ملفات معدلة مع 120 إضافات و41 حذوفات

عرض الملف

@@ -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