Skip to content

Commit 8f33e35

Browse files
committed
Make idler test more specific.
1 parent ef973e7 commit 8f33e35

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

test/async/idler.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414

1515
it "can schedule tasks up to the desired load" do
1616
expect(Fiber.scheduler.load).to be < 0.1
17+
slept = Async::Promise.new
18+
19+
mock(idler) do |mock|
20+
mock.after(:sleep) do
21+
slept.resolve(Fiber.scheduler.load)
22+
end
23+
end
1724

1825
# Generate the load:
19-
Async do
26+
task = Async do
2027
while true
2128
idler.async do
2229
while true
@@ -26,12 +33,9 @@
2633
end
2734
end
2835

29-
# This test must be longer than the idle calculation window (1s)...
30-
sleep 2.0
31-
32-
# Verify that the load is within the desired range:
33-
# Allow generous tolerance for scheduling variations on slow CI
34-
expect(Fiber.scheduler.load).to be_within(0.35).of(0.5)
36+
expect(slept.wait).to be >= 0.5
37+
ensure
38+
task.stop
3539
end
3640

3741
it_behaves_like Async::ChainableAsync

0 commit comments

Comments
 (0)