From af953ca3348d8989bbc2f0e0ee47ca7789658b65 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 13 Jun 2023 11:56:06 -0700 Subject: [PATCH] Make SEQUEL_DEFAULT_CONNECTION_POOL environment variable handle sharding If the :servers option is present, but the environment variable is not for a sharded pool, automatically switch to a sharded version. This allows all specs to pass with SEQUEL_DEFAULT_CONNECTION_POOL=timed_queue on Ruby 3.2. --- lib/sequel/connection_pool.rb | 3 ++- spec/core/connection_pool_spec.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/sequel/connection_pool.rb b/lib/sequel/connection_pool.rb index afdce1f4c..a789e1242 100644 --- a/lib/sequel/connection_pool.rb +++ b/lib/sequel/connection_pool.rb @@ -65,7 +65,8 @@ def connection_pool_class(opts) pc elsif pc = ENV['SEQUEL_DEFAULT_CONNECTION_POOL'] - connection_pool_class(:pool_class=>ENV['SEQUEL_DEFAULT_CONNECTION_POOL']) + pc = "sharded_#{pc}" if opts[:servers] && !pc.start_with?('sharded_') + connection_pool_class(:pool_class=>pc) else pc = if opts[:single_threaded] opts[:servers] ? :sharded_single : :single diff --git a/spec/core/connection_pool_spec.rb b/spec/core/connection_pool_spec.rb index 2e5b90e81..14272b2b2 100644 --- a/spec/core/connection_pool_spec.rb +++ b/spec/core/connection_pool_spec.rb @@ -82,6 +82,10 @@ def available_connections(server=:default) ENV['SEQUEL_DEFAULT_CONNECTION_POOL'] = 'sharded_threaded' pool = Sequel::ConnectionPool.get_pool(mock_db.call) pool.must_be_instance_of Sequel::ShardedThreadedConnectionPool + + ENV['SEQUEL_DEFAULT_CONNECTION_POOL'] = 'single' + pool = Sequel::ConnectionPool.get_pool(mock_db.call, :servers=>{}) + pool.must_be_instance_of Sequel::ShardedSingleConnectionPool ensure ENV.delete('SEQUEL_DEFAULT_CONNECTION_POOL') end