我试图用RSpec重现比赛条件问题。 我花了一天时间搜索周围,到目前为止我有:
def create_concurrent_calls(object, method, params=[])
processes = 2.times.map do |i|
ForkBreak::Process.new do |breakpoints|
original_method = object.method(method)
object.stub(method) do |*args|
value = original_method.call(*args)
breakpoints << method
value
end
object.send(method, *params)
end
end
processes.each{|process| process.run_until(method).wait}
processes.each{|process| process.finish.wait}
end
describe "My code issuer" do
let!(:category) { create(:category) }
let!(:code) { category.codes.create(code: 'code1') }
self.use_transactional_fixtures = false
it "returns different codes for each" do
expect(PregeneratedRedemptionCode.available.count).to be > 0
create_concurrent_calls(Code, :get_code, [category.id])
expect
... so on ..
我的描述中有self.use_transactional_fixtures = false
,但似乎无法正常工作。如果找不到该类别的代码,我的get_code方法将引发StandardError,并且每次运行我的规范时它都会弹出。虽然我期望expect(Code.count).to be > 0
通过。
任何帮助将不胜感激。感谢