如何测试成功返回主线程的线程数等于在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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.