Skip to content

Instantly share code, notes, and snippets.

@jrafanie
Last active May 10, 2016 15:46
Show Gist options
  • Save jrafanie/a27f713e791875a45a007aebb013e539 to your computer and use it in GitHub Desktop.
Save jrafanie/a27f713e791875a45a007aebb013e539 to your computer and use it in GitHub Desktop.
Connection pool swapping back to the AR::Base pool requires new step as of rails commit fcb223d (merge of #24844)
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
index fc5ca88..d171ea7 100644
--- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -21,6 +21,34 @@ def test_establish_connection_uses_spec_name
@handler.remove_connection('readonly')
end
+ def test_a_class_using_custom_pool_and_switching_back_to_primary
+ klass2 = Class.new(Base) { def self.name; 'klass2'; end }
+
+ # AR::Base's primary connection pool has a size of 5 by default
+ connection = klass2.connection
+ assert_equal(connection.pool.size, 5)
+
+ # Create a new pool for this class using pool 10
+ pool = klass2.establish_connection(adapter: 'sqlite3', pool: 10, :database => "activerecord_unittest")
+ begin
+ conn = pool.connection
+ assert_equal(conn.pool.size, 10)
+ ensure
+ # Drop the customized connection pool
+ klass2.remove_connection
+
+ # Either of the two lines below fixes this test on master/5-0-stable
+ # but are not obvious. Should remove_connection being doing this?
+ # Is this a change in behavior we need to warn about?
+ # They are not required prior to fcb223d (merge of #24844).
+ #
+ # klass2.establish_connection
+ # klass2.connection_specification_name = "primary"
+
+ # Verify, we're back to the default pool size of 5
+ assert_equal(klass2.connection.pool.size, 5)
+ end
+ end
+
def test_retrieve_connection
assert @handler.retrieve_connection(@spec_name)
end
11:34:56 ~/Code/rails/activerecord (master) (2.2.4) + git checkout 5-0-stable
...
11:34:59 ~/Code/rails/activerecord (5-0-stable) (2.2.4) + git pull
Current branch 5-0-stable is up to date.
11:35:56 ~/Code/rails/activerecord (5-0-stable) (2.2.4) - bundle
...
11:36:05 ~/Code/rails/activerecord (5-0-stable) (2.2.4) + be ruby -Itest -I test test/cases/connection_adapters/connection_handler_test.rb
Using postgresql
Run options: --seed 30039
# Running:
........E
Finished in 0.120750s, 74.5342 runs/s, 107.6605 assertions/s.
1) Error:
ActiveRecord::ConnectionAdapters::ConnectionHandlerTest#test_a_class_using_custom_pool_and_switching_back_to_primary:
ActiveRecord::ConnectionNotEstablished: No connection pool with id klass2 found.
/Users/joerafaniello/Code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:876:in `retrieve_connection'
/Users/joerafaniello/Code/rails/activerecord/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
/Users/joerafaniello/Code/rails/activerecord/lib/active_record/connection_handling.rb:91:in `connection'
test/cases/connection_adapters/connection_handler_test.rb:49:in `test_a_class_using_custom_pool_and_switching_back_to_primary'
9 runs, 13 assertions, 0 failures, 1 errors, 0 skips
11:39:16 ~/Code/rails/activerecord (5-0-stable) (2.2.4) - git checkout fcb223dd53f75bc299c267341d09791be822b0a9~
...
11:39:22 ~/Code/rails/activerecord ((bf876aa...)) (2.2.4) + be ruby -Itest -I test test/cases/connection_adapters/connection_handler_test.rb
Using postgresql
Run options: --seed 8128
# Running:
..........
Finished in 0.121621s, 82.2226 runs/s, 131.5562 assertions/s.
10 runs, 16 assertions, 0 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment