Skip to content

Commit 420440b

Browse files
committed
Addressed more intermittently failing specs.
1 parent d4d3afe commit 420440b

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

spec/concurrent/executor/global_thread_pool_shared.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
end
1616

1717
it 'calls the block with the given arguments' do
18-
@expected = nil
18+
latch = Concurrent::CountDownLatch.new(1)
19+
expected = nil
1920
subject.post(1, 2, 3) do |a, b, c|
20-
@expected = a + b + c
21+
expected = [a, b, a]
22+
latch.count_down
2123
end
22-
sleep(0.1)
23-
@expected.should eq 6
24+
latch.wait(0.2)
25+
expected.should eq [1, 2, 3]
2426
end
2527

2628
it 'aliases #<<' do
27-
@expected = false
28-
subject << proc { @expected = true }
29-
sleep(0.1)
30-
@expected.should be_true
29+
latch = Concurrent::CountDownLatch.new(1)
30+
subject << proc { latch.count_down }
31+
latch.wait(0.2)
32+
latch.count.should eq 0
3133
end
3234
end
3335
end

spec/concurrent/scheduled_task_spec.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,15 @@ def execute_dereferenceable(subject)
222222
attr_reader :value
223223
attr_reader :reason
224224
attr_reader :count
225-
define_method(:update) do |time, value, reason|
225+
attr_reader :latch
226+
def initialize
227+
@latch = Concurrent::CountDownLatch.new(1)
228+
end
229+
def update(time, value, reason)
226230
@count = @count.to_i + 1
227231
@value = value
228232
@reason = reason
233+
@latch.count_down
229234
end
230235
end
231236
end
@@ -269,17 +274,15 @@ def execute_dereferenceable(subject)
269274
it 'notifies all observers on fulfillment' do
270275
task = ScheduledTask.new(0.1){ 42 }.execute
271276
task.add_observer(observer)
272-
task.value(1).should == 42
273-
task.reason.should be_nil
277+
observer.latch.wait(1)
274278
observer.value.should == 42
275279
observer.reason.should be_nil
276280
end
277281

278282
it 'notifies all observers on rejection' do
279283
task = ScheduledTask.new(0.1){ raise StandardError }.execute
280284
task.add_observer(observer)
281-
task.value(1).should be_nil
282-
task.reason.should be_a(StandardError)
285+
observer.latch.wait(1)
283286
observer.value.should be_nil
284287
observer.reason.should be_a(StandardError)
285288
end

0 commit comments

Comments
 (0)