Skip to content

Commit 3111149

Browse files
committed
Use #wait instead of sleeping in Promise specs
The spec seems fragile otherwise
1 parent 1f196b6 commit 3111149

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

spec/concurrent/promise_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,22 @@ module Concurrent
270270

271271
it 'succeeds if both promises succeed' do
272272
child = Promise.new(executor: executor) { 1 }.
273-
flat_map { |v| Promise.new(executor: executor) { v + 10 } }.execute
274-
sleep 0.1
273+
flat_map { |v| Promise.new(executor: executor) { v + 10 } }.execute.wait
274+
275275
expect(child.value!).to eq(11)
276276
end
277277

278278
it 'fails if the left promise fails' do
279279
child = Promise.new(executor: executor) { fail }.
280-
flat_map { |v| Promise.new(executor: executor) { v + 10 } }.execute
281-
sleep 0.1
280+
flat_map { |v| Promise.new(executor: executor) { v + 10 } }.execute.wait
281+
282282
expect(child).to be_rejected
283283
end
284284

285285
it 'fails if the right promise fails' do
286286
child = Promise.new(executor: executor) { 1 }.
287-
flat_map { |v| Promise.new(executor: executor) { fail } }.execute
288-
sleep 0.1
287+
flat_map { |v| Promise.new(executor: executor) { fail } }.execute.wait
288+
289289
expect(child).to be_rejected
290290
end
291291

@@ -297,14 +297,14 @@ module Concurrent
297297
let(:promise3) { Promise.new(executor: executor) { [3] } }
298298

299299
it 'yields the results as an array' do
300-
composite = promise1.zip(promise2, promise3).execute
301-
sleep 0.1
300+
composite = promise1.zip(promise2, promise3).execute.wait
301+
302302
expect(composite.value).to eq([1, 2, [3]])
303303
end
304304

305305
it 'fails if one component fails' do
306-
composite = promise1.zip(promise2, rejected_subject, promise3).execute
307-
sleep 0.1
306+
composite = promise1.zip(promise2, rejected_subject, promise3).execute.wait
307+
308308
expect(composite).to be_rejected
309309
end
310310
end

0 commit comments

Comments
 (0)