diff --git a/activerecord/test/cases/hot_compatibility_test.rb b/activerecord/test/cases/hot_compatibility_test.rb index e97be4a2fc8a7ad43c163efd411846f133b7a035..9fc75b73774876da171356bf1064cd64902b9ae9 100644 --- a/activerecord/test/cases/hot_compatibility_test.rb +++ b/activerecord/test/cases/hot_compatibility_test.rb @@ -64,6 +64,9 @@ def self.name; 'HotCompatibility'; end record.reload end + assert get_prepared_statement_cache(@klass.connection).any?, + "expected prepared statement cache to have something in it" + # add a new column ddl_connection.add_column :hot_compatibilities, :baz, :string @@ -73,11 +76,7 @@ def self.name; 'HotCompatibility'; end end end - prepared_statement_cache = @klass.connection - .instance_variable_get(:@statements) - .instance_variable_get(:@cache)[Process.pid] - - assert_empty prepared_statement_cache, + assert_empty get_prepared_statement_cache(@klass.connection), "expected prepared statement cache to be empty but it wasn't" end end @@ -91,6 +90,9 @@ def self.name; 'HotCompatibility'; end record.reload end + assert get_prepared_statement_cache(@klass.connection).any?, + "expected prepared statement cache to have something in it" + # add a new column ddl_connection.add_column :hot_compatibilities, :baz, :string @@ -104,11 +106,7 @@ def self.name; 'HotCompatibility'; end end end - prepared_statement_cache = @klass.connection - .instance_variable_get(:@statements) - .instance_variable_get(:@cache)[Process.pid] - - assert_empty prepared_statement_cache, + assert_empty get_prepared_statement_cache(@klass.connection), "expected prepared statement cache to be empty but it wasn't" end end @@ -116,6 +114,11 @@ def self.name; 'HotCompatibility'; end private + def get_prepared_statement_cache(connection) + connection.instance_variable_get(:@statements) + .instance_variable_get(:@cache)[Process.pid] + end + # Rails will automatically clear the prepared statements on the connection # that runs the migration, so we use two connections to simulate what would # actually happen on a production system; we'd have one connection running the