Skip to content

Commit

Permalink
Remove excessively long error messages. Fix specs for Rails 3.2.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Durand committed Nov 8, 2012
1 parent db48696 commit 4bbc362
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.0.12

Remove excessively long log messages on reconnect attempts.

1.0.11

Remove debug code that prevented recovering from errors.

1.0.10

Compatibility with ActiveRecord 3.1.0
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.11
1.0.12
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def available_read_connections
available = @available_read_connections.last
if available.expired?
begin
@logger.info("Adding dead database connection back to the pool: #{available.inspect}") if @logger
@logger.info("Adding dead database connection back to the pool") if @logger
available.reconnect!
rescue => e
# Couldn't reconnect so try again in a little bit
if @logger
@logger.warn("Failed to reconnect with: #{available.inspect}")
@logger.warn("Failed to reconnect to database when adding connection back to the pool")
@logger.warn(e)
end
available.expires = 30.seconds.from_now
Expand Down
5 changes: 2 additions & 3 deletions spec/connection_adapters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

before(:all) do
ActiveRecord::Base.establish_connection('adapter' => "sqlite3", 'database' => ":memory:")
model.use_database_connection(adapter)
model.create_tables
end

Expand Down Expand Up @@ -143,7 +142,7 @@

it "should send tables to the read connection" do
results = connection.tables
results.should == ["test_models"]
results.should == [model.table_name]
results.should == master_connection.tables
results.should be_read_only
end
Expand Down Expand Up @@ -209,7 +208,7 @@
it "should properly dump the schema" do
schema = <<-EOS
ActiveRecord::Schema.define(:version => 0) do
create_table "test_models", :force => true do |t|
create_table "#{model.table_name}", :force => true do |t|
t.string "name"
t.integer "value"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ postgresql:
mysql:
adapter: seamless_database_pool
database: seamless_database_pool_test
username: root
password:
master:
adapter: mysql
pool_weight: 0
Expand Down
10 changes: 9 additions & 1 deletion spec/test_model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module SeamlessDatabasePool
class TestModel < ActiveRecord::Base
self.abstract_class = true

class << self
def database_configs
adapters = ENV['TEST_ADAPTERS'].blank? ? [] : ENV['TEST_ADAPTERS'].split(/\s+/)
Expand All @@ -15,10 +17,12 @@ def use_database_connection(db_name)
end

def db_model(db_name)
model_class_name = db_name.classify
model_class_name = "#{db_name.classify}TestModel"
unless const_defined?(model_class_name)
klass = Class.new(self)
const_set(model_class_name, klass)
klass = const_get(model_class_name)
klass.use_database_connection(db_name)
end
const_get(model_class_name)
end
Expand All @@ -28,10 +32,14 @@ def create_tables
t.column :name, :string
t.column :value, :integer
end unless table_exists?
connection.clear_cache!
undefine_attribute_methods
end

def drop_tables
connection.drop_table(table_name)
connection.clear_cache!
undefine_attribute_methods
end

def cleanup_database!
Expand Down

0 comments on commit 4bbc362

Please sign in to comment.