提交 66762b81 编写于 作者: Q Quan Chau

Wrap Mysql count of deleted rows in lock block to avoid conflict in test

上级 95a1d872
......@@ -61,7 +61,9 @@ def exec_query(sql, name = "SQL", binds = [], prepare: false)
def exec_delete(sql, name = nil, binds = [])
if without_prepared_statement?(binds)
execute_and_free(sql, name) { @connection.affected_rows }
@lock.synchronize do
execute_and_free(sql, name) { @connection.affected_rows }
end
else
exec_stmt_and_free(sql, name, binds) { |stmt| stmt.affected_rows }
end
......
# frozen_string_literal: true
require "cases/helper"
require "support/connection_helper"
require "models/author"
require "models/bulb"
module ActiveRecord
class CountDeletedRowsWithLockTest < ActiveRecord::Mysql2TestCase
test "delete and create in different threads synchronize correctly" do
Bulb.unscoped.delete_all
Bulb.create!(name: "Jimmy", color: "blue")
delete_thread = Thread.new do
Bulb.unscoped.delete_all
end
create_thread = Thread.new do
Author.create!(name: "Tommy")
end
delete_thread.join
create_thread.join
assert_equal 1, delete_thread.value
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册