diff options
author | Matthew Draper <matthew@trebex.net> | 2016-10-01 16:04:42 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-10-01 16:04:42 +0930 |
commit | eabff0daa8b1f4273d500dbd77ef76e1e0ca6e9a (patch) | |
tree | 06079cf379af5b7b7b1c77502c6f29529905841e /activerecord/test | |
parent | 9588a3d66d4ca6ba122d32417aa62680f441bf40 (diff) | |
download | rails-eabff0daa8b1f4273d500dbd77ef76e1e0ca6e9a.tar.gz rails-eabff0daa8b1f4273d500dbd77ef76e1e0ca6e9a.tar.bz2 rails-eabff0daa8b1f4273d500dbd77ef76e1e0ca6e9a.zip |
Make PG deadlock error more deterministic
We've seen occasional Travis failures mentioning deadlocks. I think
they're escaping from this test.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/transaction_test.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/transaction_test.rb b/activerecord/test/cases/adapters/postgresql/transaction_test.rb index d992e22305..00119f13bb 100644 --- a/activerecord/test/cases/adapters/postgresql/transaction_test.rb +++ b/activerecord/test/cases/adapters/postgresql/transaction_test.rb @@ -1,5 +1,6 @@ require "cases/helper" require "support/connection_helper" +require "concurrent/atomic/cyclic_barrier" module ActiveRecord class PostgresqlTransactionTest < ActiveRecord::PostgreSQLTestCase @@ -61,26 +62,28 @@ module ActiveRecord test "raises Deadlocked when a deadlock is encountered" do with_warning_suppression 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 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 |