aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/adapters/mysql2/transaction_test.rb22
-rw-r--r--activerecord/test/cases/adapters/postgresql/transaction_test.rb4
2 files changed, 17 insertions, 9 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/transaction_test.rb b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
index edd5353ee3..b37abd7e2e 100644
--- a/activerecord/test/cases/adapters/mysql2/transaction_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
@@ -29,26 +29,30 @@ module ActiveRecord
test "raises Deadlocked when a deadlock is encountered" do
assert_raises(ActiveRecord::Deadlocked) do
+ barrier = Concurrent::CyclicBarrier.new(2)
+
s1 = Sample.create value: 1
s2 = Sample.create value: 2
thread = Thread.new do
+ Thread.current.abort_on_exception = false
+
Sample.transaction do
s1.lock!
- sleep 1
+ barrier.wait
s2.update_attributes value: 1
end
end
- sleep 0.5
-
- Sample.transaction do
- s2.lock!
- sleep 1
- s1.update_attributes value: 2
+ begin
+ Sample.transaction do
+ s2.lock!
+ barrier.wait
+ s1.update_attributes value: 2
+ end
+ ensure
+ thread.join
end
-
- thread.join
end
end
end
diff --git a/activerecord/test/cases/adapters/postgresql/transaction_test.rb b/activerecord/test/cases/adapters/postgresql/transaction_test.rb
index c450524de8..372af6b2be 100644
--- a/activerecord/test/cases/adapters/postgresql/transaction_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/transaction_test.rb
@@ -33,6 +33,8 @@ module ActiveRecord
after = Concurrent::CyclicBarrier.new(2)
thread = Thread.new do
+ Thread.current.abort_on_exception = false
+
with_warning_suppression do
Sample.transaction isolation: :serializable do
before.wait
@@ -65,6 +67,8 @@ module ActiveRecord
s2 = Sample.create value: 2
thread = Thread.new do
+ Thread.current.abort_on_exception = false
+
Sample.transaction do
s1.lock!
barrier.wait