提交 eabff0da 编写于 作者: M Matthew Draper

Make PG deadlock error more deterministic

We've seen occasional Travis failures mentioning deadlocks. I think
they're escaping from this test.
上级 9588a3d6
require "cases/helper"
require "support/connection_helper"
require "concurrent/atomic/cyclic_barrier"
module ActiveRecord
class PostgresqlTransactionTest < ActiveRecord::PostgreSQLTestCase
......@@ -61,26 +62,28 @@ class Sample < ActiveRecord::Base
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册