diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-11 19:18:17 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-11-11 19:18:17 +0900 |
commit | ee5cf14ab06c366b37a6339f2af7c41457b3557b (patch) | |
tree | b16d0ae6a8790dda7b09b5098b389dc66212d823 /activerecord/test/cases | |
parent | 24b59434e6aca9679b9f86a41cfbb1a33e3d5619 (diff) | |
download | rails-ee5cf14ab06c366b37a6339f2af7c41457b3557b.tar.gz rails-ee5cf14ab06c366b37a6339f2af7c41457b3557b.tar.bz2 rails-ee5cf14ab06c366b37a6339f2af7c41457b3557b.zip |
Should test actual error which is raised from the database
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/mysql2/transaction_test.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/transaction_test.rb b/activerecord/test/cases/adapters/mysql2/transaction_test.rb index 25d9f69a89..7b032fed6d 100644 --- a/activerecord/test/cases/adapters/mysql2/transaction_test.rb +++ b/activerecord/test/cases/adapters/mysql2/transaction_test.rb @@ -62,7 +62,29 @@ module ActiveRecord test "raises TransactionTimeout when mysql raises ER_LOCK_WAIT_TIMEOUT" do assert_raises(ActiveRecord::TransactionTimeout) do - ActiveRecord::Base.connection.execute("SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = 'Testing error', MYSQL_ERRNO = 1205;") + s = Sample.create!(value: 1) + latch1 = Concurrent::CountDownLatch.new + latch2 = Concurrent::CountDownLatch.new + + thread = Thread.new do + Sample.transaction do + Sample.lock.find(s.id) + latch1.count_down + latch2.wait + end + end + + begin + Sample.transaction do + latch1.wait + Sample.connection.execute("SET innodb_lock_wait_timeout = 1") + Sample.lock.find(s.id) + end + ensure + Sample.connection.execute("SET innodb_lock_wait_timeout = DEFAULT") + latch2.count_down + thread.join + end end end end |