Skip to content

Commit 6bdff8b

Browse files
zzakbyroot
authored andcommitted
Add timeout to avoid nested deadlock flakey test
Due to the large number of times I ran the whole suite to debugging other flakey tests, I was able to reproduce the issue similar to rails#49841. That issue has still happened recently, but as we've noted (can't find the ticket now) that the Active Record tests sometimes run other adapter's tests leading to confusion that it might be specific to sqlite, but it's not. I can reproduce this by running the tests with mysql2 many many times, eventually it hangs. And when it does the last thing in `debug.log`: ``` ActiveRecord::NestedDeadlockTest::Sample Pluck (0.1ms) SELECT `samples`.`value` FROM `samples` (5.3ms) DROP TABLE IF EXISTS `samples` (1.1ms) DROP TABLE IF EXISTS `samples` (7.1ms) CREATE TABLE `samples` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, `value` int) TRANSACTION (0.0ms) BEGIN ActiveRecord::NestedDeadlockTest::Sample Create (0.2ms) INSERT INTO `samples` (`value`) VALUES (?) [["value", 1]] TRANSACTION (1.4ms) COMMIT TRANSACTION (0.0ms) BEGIN ActiveRecord::NestedDeadlockTest::Sample Create (0.1ms) INSERT INTO `samples` (`value`) VALUES (?) [["value", 2]] TRANSACTION (1.6ms) COMMIT TRANSACTION (0.2ms) BEGIN TRANSACTION (0.1ms) BEGIN ActiveRecord::NestedDeadlockTest::Sample Load (0.3ms) SELECT `samples`.* FROM `samples` LIMIT ? [["LIMIT", 1]] TRANSACTION (0.0ms) SAVEPOINT active_record_1 ActiveRecord::NestedDeadlockTest::Sample Load (0.4ms) SELECT `samples`.* FROM `samples` LIMIT ? [["LIMIT", 1]] ActiveRecord::NestedDeadlockTest::Sample Load (0.4ms) SELECT `samples`.* FROM `samples` WHERE `samples`.`id` = ? LIMIT ? FOR UPDATE [["id", 2], ["LIMIT", 1]] TRANSACTION (0.1ms) SAVEPOINT active_record_1 TRANSACTION (0.0ms) ROLLBACK TO SAVEPOINT active_record_1 ActiveRecord::NestedDeadlockTest::Sample Load (0.3ms) SELECT `samples`.* FROM `samples` WHERE `samples`.`id` = ? LIMIT ? FOR UPDATE [["id", 1], ["LIMIT", 1]] TRANSACTION (0.4ms) ROLLBACK ``` I tried gdb, strace, lsof, but the logs were always on the same test class when it happened. I have a coredump if anyone one the team wants to take a look.
1 parent 5f53cf9 commit 6bdff8b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

activerecord/test/cases/adapters/abstract_mysql_adapter/nested_deadlock_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Sample < ActiveRecord::Base
4848
Sample.transaction(requires_new: true) do
4949
assert_current_transaction_is_savepoint_transaction
5050
s1.lock!
51-
barrier.wait
51+
barrier.wait(30)
5252
s2.update value: 1
5353
end
5454
end
@@ -60,7 +60,7 @@ class Sample < ActiveRecord::Base
6060
Sample.transaction(requires_new: true) do
6161
assert_current_transaction_is_savepoint_transaction
6262
s2.lock!
63-
barrier.wait
63+
barrier.wait(30)
6464
s1.update value: 2
6565
end
6666
end
@@ -91,7 +91,7 @@ class Sample < ActiveRecord::Base
9191
Sample.transaction(requires_new: true) do
9292
assert_current_transaction_is_savepoint_transaction
9393
s1.lock!
94-
barrier.wait
94+
barrier.wait(30)
9595
s2.update value: 4
9696

9797
rescue ActiveRecord::Deadlocked
@@ -113,7 +113,7 @@ class Sample < ActiveRecord::Base
113113
Sample.transaction(requires_new: true) do
114114
assert_current_transaction_is_savepoint_transaction
115115
s2.lock!
116-
barrier.wait
116+
barrier.wait(30)
117117
s1.update value: 3
118118
rescue ActiveRecord::Deadlocked
119119
deadlocks += 1
@@ -143,7 +143,7 @@ class Sample < ActiveRecord::Base
143143
Sample.transaction(requires_new: true) do
144144
assert_current_transaction_is_savepoint_transaction
145145
s1.lock!
146-
barrier.wait
146+
barrier.wait(30)
147147
s2.update value: 4
148148
end
149149
rescue ActiveRecord::Deadlocked
@@ -160,7 +160,7 @@ class Sample < ActiveRecord::Base
160160
Sample.transaction(requires_new: true) do
161161
assert_current_transaction_is_savepoint_transaction
162162
s2.lock!
163-
barrier.wait
163+
barrier.wait(30)
164164
s1.update value: 3
165165
end
166166
rescue ActiveRecord::Deadlocked

0 commit comments

Comments
 (0)