Skip to content

Commit

Permalink
Fix handling of invalid :pool_class symbols
Browse files Browse the repository at this point in the history
Previously you couldn't hit the error, because the require
would raise a LoadError.  It doesn't make sense to allow requiring
random files if there is no way to register the entries.  In
Sequel 5, non default pool classes need to be specified by having
the :pool_class be a class instead of a non-default symbol.
  • Loading branch information
jeremyevans committed Aug 1, 2017
1 parent 64e26d3 commit e01b004
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/sequel/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
# specified by the array of symbols.
class Sequel::ConnectionPool
OPTS = Sequel::OPTS
POOL_CLASS_MAP = {
:threaded => :ThreadedConnectionPool,
:single => :SingleConnectionPool,
:sharded_threaded => :ShardedThreadedConnectionPool,
:sharded_single => :ShardedSingleConnectionPool
}.freeze

# Class methods used to return an appropriate pool subclass, separated
# into a module for easier overridding by extensions.
Expand All @@ -44,20 +50,12 @@ def get_pool(db, opts = OPTS)
def connection_pool_class(opts)
if pc = opts[:pool_class]
unless pc.is_a?(Class)
require("sequel/connection_pool/#{pc}")

pc = case pc
when :threaded
Sequel::ThreadedConnectionPool
when :single
Sequel::SingleConnectionPool
when :sharded_threaded
Sequel::ShardedThreadedConnectionPool
when :sharded_single
Sequel::ShardedSingleConnectionPool
else
unless name = POOL_CLASS_MAP[pc]
raise Sequel::Error, "unsupported connection pool type, please pass appropriate class as the :pool_class option"
end

require("sequel/connection_pool/#{pc}")
pc = Sequel.const_get(name)
end

pc
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 @@ -31,6 +31,10 @@
it "should have a size of zero" do
@cpool.size.must_equal 0
end

it "should raise Error for bad pool class" do
proc{Sequel::ConnectionPool.get_pool(mock_db.call, :pool_class=>:foo)}.must_raise Sequel::Error
end
end

describe "ConnectionPool options" do
Expand Down

0 comments on commit e01b004

Please sign in to comment.