如何测试成功返回主线程的线程数是否等于rspec中创建的线程数?
最佳答案
describe '#update_tokens' do
it 'is threadsafe', db_strategy: :truncation do
u = create(:user)
thread_injected = false
time = Time.now
allow(Time).to receive(:now) do
unless thread_injected
thread_injected = true
Thread.new { u.reload.update_tokens('c2', 't2') }.join
end
time
end
u.update_tokens('c1', 't1')
expect(u.tokens['c1']).not_to be_nil
expect(u.tokens['c2']).not_to be_nil
end
end
关于ruby - 使用 rspec 测试成功返回的线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45469849/