如何修复 Minitest 中的 Postgres 死锁错误?

问题描述 投票:0回答:1

我正在使用 Minitest 和 Postgres 来测试我的 Rails 网站。当我添加模型和控制器的测试时,我开始在不同的测试中遇到 Postgresql 死锁错误。

更新

我发现问题了。当测试太多时我会收到这些错误。我进行了 50 次测试,一切正常。当我添加更多测试时,我会收到错误。我该如何修复它们?

错误:

Minitest::UnexpectedError: ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR:  deadlock detected LINE 7: DELETE FROM "videos";                     ^ DETAIL:  Process 11456 waits for RowExclusiveLock on relation 42608 of database 42434; blocked by process 10460. Process 10460 waits for ShareRowExclusiveLock on relation 42564 of database 42434; blocked by process 11456. HINT:  See server log for query details. 

其他错误:

Minitest::UnexpectedError: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "accounts_pkey"
DETAIL:  Key (id)=(825136781) already exists.
Minitest::UnexpectedError: ActiveRecord::ConnectionNotEstablished: connection is closed
ruby-on-rails ruby postgresql deadlock minitest
1个回答
0
投票

在 test_helper.rb 中注释此行

parallelize(workers: :number_of_processors, with: :threads)
© www.soinside.com 2019 - 2024. All rights reserved.