Skip to content

Commit

Permalink
Make SEQUEL_DEFAULT_CONNECTION_POOL environment variable handle sharding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeremyevans committed Jun 13, 2023
1 parent f0916af commit af953ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sequel/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/core/connection_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af953ca

Please sign in to comment.