-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add pool_timeout and max_connections parameters #11
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,11 @@ class << self | |
# Start the Sequel connection with the configured database | ||
def start(config) | ||
params = config.to_hash.select { |k, v| !v.nil? } | ||
# using sequel default values. | ||
max_connections = params[:max_connections]||4 | ||
pool_timeout = params[:pool_timeout]||5 | ||
|
||
@@connection = establish_connection connection_string(params) | ||
@@connection = establish_connection(connection_string(params),max_connections,pool_timeout) | ||
require_models(*params.delete(:model_paths)) | ||
|
||
# Provide Sequel a handle on the Adhearsion logger | ||
|
@@ -52,9 +55,9 @@ def qualify_path(path) | |
# Start the Sequel connection with the configured database | ||
# | ||
# @param connection_uri [String] Connection URI for connecting to the database | ||
def establish_connection(connection_uri) | ||
def establish_connection(connection_uri, max_connections, pool_timeout) | ||
logger.info "Sequella connecting: #{connection_uri}" | ||
::Sequel.connect connection_uri | ||
::Sequel.connect connection_uri, :max_connections => max_connections, :pool_timeout => pool_timeout | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Ruby 1.9 hash syntax (eg. |
||
end | ||
|
||
## | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,29 @@ | |
describe '#start' do | ||
it 'should not raise an error if start attempted with a uri specified' do | ||
config = OpenStruct.new uri: 'postgres://user:password@localhost/blog' | ||
subject.should_receive(:establish_connection).with(config.uri) | ||
subject.should_receive(:establish_connection).with(config.uri,4,5) | ||
subject.should_receive(:require_models) | ||
|
||
expect { subject.start config.marshal_dump }.to_not raise_error | ||
end | ||
it 'should pass configured pool value' do | ||
connection_params = { | ||
adapter: 'postgres', | ||
host: 'localhost', | ||
port: 5432, | ||
database: 'test', | ||
username: 'test-user', | ||
password: 'password', | ||
max_connections: 20, | ||
pool_timeout: 10 | ||
} | ||
|
||
subject.should_receive(:establish_connection).with('postgres://test-user:password@localhost:5432/test',20,10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to place the expectation on the |
||
subject.should_receive(:require_models) | ||
|
||
expect { subject.start connection_params }.to_not raise_error | ||
|
||
end | ||
end | ||
|
||
describe '#connection_string' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit, but would you please add spaces after the commas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it occurs to me that it might be better to pass this as a hash to
#establish_connection
, in case we get more params in the future. The calling code would then look something like