diff options
author | Matthew Draper <matthew@trebex.net> | 2016-10-07 09:28:36 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-10-07 09:28:36 +1030 |
commit | 3127e99d6e0d89149dca5c4815474b69012a86b7 (patch) | |
tree | ca911e3fd321c19930cbd1cd0baeb20d6b035546 | |
parent | 3a11c5b626fcd781e3bacd4a59003465e9aafb5f (diff) | |
download | rails-3127e99d6e0d89149dca5c4815474b69012a86b7.tar.gz rails-3127e99d6e0d89149dca5c4815474b69012a86b7.tar.bz2 rails-3127e99d6e0d89149dca5c4815474b69012a86b7.zip |
Simplify serializable test to avoid mystery deadlock
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/transaction_test.rb | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/transaction_test.rb b/activerecord/test/cases/adapters/postgresql/transaction_test.rb index 00119f13bb..c450524de8 100644 --- a/activerecord/test/cases/adapters/postgresql/transaction_test.rb +++ b/activerecord/test/cases/adapters/postgresql/transaction_test.rb @@ -28,32 +28,29 @@ module ActiveRecord end test "raises SerializationFailure when a serialization failure occurs" do - with_warning_suppression do - assert_raises(ActiveRecord::SerializationFailure) do - thread = Thread.new do - Sample.transaction isolation: :serializable do - Sample.delete_all + assert_raises(ActiveRecord::SerializationFailure) do + before = Concurrent::CyclicBarrier.new(2) + after = Concurrent::CyclicBarrier.new(2) - 10.times do |i| - sleep 0.1 - - Sample.create value: i - end + thread = Thread.new do + with_warning_suppression do + Sample.transaction isolation: :serializable do + before.wait + Sample.create value: Sample.sum(:value) + after.wait end end + end - sleep 0.1 - - Sample.transaction isolation: :serializable do - Sample.delete_all - - 10.times do |i| - sleep 0.1 - - Sample.create value: i + begin + with_warning_suppression do + Sample.transaction isolation: :serializable do + before.wait + Sample.create value: Sample.sum(:value) + after.wait end end - + ensure thread.join end end @@ -91,10 +88,11 @@ module ActiveRecord protected def with_warning_suppression - log_level = @connection.client_min_messages - @connection.client_min_messages = "error" + log_level = ActiveRecord::Base.connection.client_min_messages + ActiveRecord::Base.connection.client_min_messages = "error" yield - @connection.client_min_messages = log_level + ensure + ActiveRecord::Base.connection.client_min_messages = log_level end end end |