From 6828ae7779c0ff1be321408027851b73a964593b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 4 Oct 2013 15:16:49 -0700 Subject: stop adding singleton methods to the mysql2 adapter --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index fedd9f603c..679c515e8c 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -3,14 +3,14 @@ require "cases/helper" class MysqlConnectionTest < ActiveRecord::TestCase def setup super + @subscriber = SQLSubscriber.new + ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber) @connection = ActiveRecord::Base.connection - @connection.extend(LogIntercepter) - @connection.intercepted = true end def teardown - @connection.intercepted = false - @connection.logged = [] + ActiveSupport::Notifications.unsubscribe(@subscriber) + super end def test_no_automatic_reconnection_after_timeout @@ -72,14 +72,14 @@ class MysqlConnectionTest < ActiveRecord::TestCase def test_logs_name_show_variable @connection.show_variable 'foo' - assert_equal "SCHEMA", @connection.logged[0][1] + assert_equal "SCHEMA", @subscriber.logged[0][1] end def test_logs_name_rename_column_sql @connection.execute "CREATE TABLE `bar_baz` (`foo` varchar(255))" - @connection.logged = [] + @subscriber.logged.clear @connection.send(:rename_column_sql, 'bar_baz', 'foo', 'foo2') - assert_equal "SCHEMA", @connection.logged[0][1] + assert_equal "SCHEMA", @subscriber.logged[0][1] ensure @connection.execute "DROP TABLE `bar_baz`" end -- cgit v1.2.3 From 5d870c929157b7c7949c9356d4f88b97c8848ec3 Mon Sep 17 00:00:00 2001 From: Doug Barth Date: Tue, 5 Nov 2013 10:04:00 -0800 Subject: Don't swallow exceptions in transctional statements The MySQL connection adapater swallows all StandardError exceptions, which includes Mysql::Error and Mysql2::Error. The comment in the exception clause claims errors thrown here indicate that transactions aren't supported by the server but that isn't necessarily true. It's possible the MySQL server has gone away and swallowing a failed commit may let the application return a successful response when the data has not been saved. Also, replication libraries like Galera require that the application handle exceptions thrown at BEGIN/COMMIT. I'm unable to determine what version of MySQL threw an exception for transactional statements. I tried as far back as 3.23.49 with InnoDB disabled but BEGIN & COMMIT statements do not throw an error. If there's a real case for this logic to continue, we could instead push this behavior into a configuration setting. The exception swallowing has been there since the beginning: db045dbbf60b53dbe013ef25554fd013baf88134 --- .../test/cases/adapters/mysql2/connection_test.rb | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 679c515e8c..943ca9d552 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -18,6 +18,11 @@ class MysqlConnectionTest < ActiveRecord::TestCase @connection.update('set @@wait_timeout=1') sleep 2 assert !@connection.active? + + # Repair all fixture connections so other tests won't break. + @fixture_connections.each do |c| + c.verify! + end end def test_successful_reconnection_after_timeout_with_manual_reconnect @@ -84,6 +89,27 @@ class MysqlConnectionTest < ActiveRecord::TestCase @connection.execute "DROP TABLE `bar_baz`" end + def test_mysql_begin_db_transaction_can_throw_an_exception + @connection.expects(:execute).with('BEGIN').raises('OH NOES') + assert_raise RuntimeError do + @connection.begin_db_transaction + end + end + + def test_mysql_commit_db_transaction_can_throw_an_exception + @connection.expects(:execute).with('COMMIT').raises('OH NOES') + assert_raise RuntimeError do + @connection.commit_db_transaction + end + end + + def test_mysql_rollback_db_transaction_can_throw_an_exception + @connection.expects(:execute).with('ROLLBACK').raises('OH NOES') + assert_raise RuntimeError do + @connection.rollback_db_transaction + end + end + private def run_without_connection -- cgit v1.2.3 From 2b0406cedb61c4c2f74ecca61fc07771e911fd35 Mon Sep 17 00:00:00 2001 From: Doug Barth Date: Fri, 15 Nov 2013 10:29:30 -0800 Subject: Remove tests for not swallowing exceptions. From PR, @tenderlove would prefer to not maintain these tests. --- .../test/cases/adapters/mysql2/connection_test.rb | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 943ca9d552..8dc1df1851 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -89,27 +89,6 @@ class MysqlConnectionTest < ActiveRecord::TestCase @connection.execute "DROP TABLE `bar_baz`" end - def test_mysql_begin_db_transaction_can_throw_an_exception - @connection.expects(:execute).with('BEGIN').raises('OH NOES') - assert_raise RuntimeError do - @connection.begin_db_transaction - end - end - - def test_mysql_commit_db_transaction_can_throw_an_exception - @connection.expects(:execute).with('COMMIT').raises('OH NOES') - assert_raise RuntimeError do - @connection.commit_db_transaction - end - end - - def test_mysql_rollback_db_transaction_can_throw_an_exception - @connection.expects(:execute).with('ROLLBACK').raises('OH NOES') - assert_raise RuntimeError do - @connection.rollback_db_transaction - end - end - private def run_without_connection -- cgit v1.2.3 From 8e2c0803f5e114f74ce0e8acc44ae43da97175e3 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 24 Dec 2013 17:28:40 -0500 Subject: Move mysql2 test for when adapter will be loaded When run with only the Mysql adapter, we get this failure: https://travis-ci.org/rails/rails/jobs/15937907#L2416 Porting the test over to only run when mysql2 is loaded --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 8dc1df1851..91b780a7ee 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -13,6 +13,13 @@ class MysqlConnectionTest < ActiveRecord::TestCase super end + def test_bad_connection + assert_raise ActiveRecord::NoDatabaseError do + connection = ActiveRecord::Base.mysql2_connection(adapter: "mysql2", database: "should_not_exist-cinco-dog-db") + connection.exec_query('drop table if exists ex') + end + end + def test_no_automatic_reconnection_after_timeout assert @connection.active? @connection.update('set @@wait_timeout=1') -- cgit v1.2.3 From 143da09f5177d66ccad6a3141f90fc275f01c754 Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Sun, 29 Dec 2013 13:57:52 +0530 Subject: used user-defined configurations for running tests that might depend on user's system configuration --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 91b780a7ee..8fe8bd7df3 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -15,7 +15,8 @@ class MysqlConnectionTest < ActiveRecord::TestCase def test_bad_connection assert_raise ActiveRecord::NoDatabaseError do - connection = ActiveRecord::Base.mysql2_connection(adapter: "mysql2", database: "should_not_exist-cinco-dog-db") + configuration = ActiveRecord::Base.configurations['arunit'].merge(database: 'should_not_exist-cinco-dog-db') + connection = ActiveRecord::Base.mysql2_connection(configuration) connection.exec_query('drop table if exists ex') end end -- cgit v1.2.3 From 85a1f7ae1e66cff7fa2cf8a1be3721da38acd579 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Wed, 1 Jan 2014 09:38:37 +0900 Subject: Change the inexistent database name to inexistent_activerecord_unittest to make this grant statement described in the document works GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.* to 'rails'@'localhost'; --- activerecord/test/cases/adapters/mysql2/connection_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test/cases/adapters/mysql2/connection_test.rb') diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 8fe8bd7df3..9b7202c915 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -15,7 +15,7 @@ class MysqlConnectionTest < ActiveRecord::TestCase def test_bad_connection assert_raise ActiveRecord::NoDatabaseError do - configuration = ActiveRecord::Base.configurations['arunit'].merge(database: 'should_not_exist-cinco-dog-db') + configuration = ActiveRecord::Base.configurations['arunit'].merge(database: 'inexistent_activerecord_unittest') connection = ActiveRecord::Base.mysql2_connection(configuration) connection.exec_query('drop table if exists ex') end -- cgit v1.2.3