2019-07-01 22:34:38 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 05:12:25 +00:00
|
|
|
RSpec.describe ConnectionPool::SharedConnectionPool do
|
2023-05-03 08:32:30 +00:00
|
|
|
subject { described_class.new(size: 5, timeout: 5) { |site| mini_connection_class.new(site) } }
|
2019-07-01 22:34:38 +00:00
|
|
|
|
2023-05-03 08:32:30 +00:00
|
|
|
let(:mini_connection_class) do
|
|
|
|
Class.new do
|
|
|
|
attr_reader :site
|
|
|
|
|
|
|
|
def initialize(site)
|
|
|
|
@site = site
|
|
|
|
end
|
2019-07-01 22:34:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#with' do
|
|
|
|
it 'runs a block with a connection' do
|
|
|
|
block_run = false
|
|
|
|
|
|
|
|
subject.with('foo') do |connection|
|
2023-05-03 08:32:30 +00:00
|
|
|
expect(connection).to be_a mini_connection_class
|
2019-07-01 22:34:38 +00:00
|
|
|
block_run = true
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(block_run).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|