Skip to content

Commit bbcd077

Browse files
headiuseregon
authored andcommitted
Only test that sleeps were long enough
This spec was originally added to confirm that sub-millisecond sleeps actually did sleep; on JRuby and TruffleRuby before fixes a sleep of 0.0001s would immediately return, because we both used a sleep function with a minimum resolution of 0.001s. Ideally 100 sleeps of 0.0001s should not exceed 0.03s, but since that's not the goal of this spec and since it makes the spec flaky under load or on slower systems, it seems best to remove this check. The remaining check just confirms that 100x sleep of 0.0001s does actually sleep for at least 0.01s. Any Ruby failing the spec now would indicate they are not actually sleeping for 0.0001s and they need a fix.
1 parent 54c391e commit bbcd077

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

core/kernel/sleep_spec.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,15 @@ def o.divmod(*); [0, 0.001]; end
5151
t.value.should == 5
5252
end
5353

54-
platform_is_not :darwin do
55-
it "sleeps with nanosecond precision" do
56-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
57-
100.times do
58-
sleep(0.0001)
59-
end
60-
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
61-
62-
actual_duration = end_time - start_time
63-
(actual_duration > 0.01).should == true # 100 * 0.0001 => 0.01
64-
(actual_duration < 0.03).should == true
54+
it "sleeps with nanosecond precision" do
55+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
56+
100.times do
57+
sleep(0.0001)
6558
end
59+
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
60+
61+
actual_duration = end_time - start_time
62+
actual_duration.should > 0.01 # 100 * 0.0001 => 0.01
6663
end
6764

6865
ruby_version_is ""..."3.3" do

0 commit comments

Comments
 (0)