From bbcd077ac3ff6da3730f388c61d4fcbbf085f4ab Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 6 Nov 2024 11:56:45 -0600 Subject: [PATCH] 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. --- core/kernel/sleep_spec.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/kernel/sleep_spec.rb b/core/kernel/sleep_spec.rb index 1de52a707..4401e5425 100644 --- a/core/kernel/sleep_spec.rb +++ b/core/kernel/sleep_spec.rb @@ -51,18 +51,15 @@ def o.divmod(*); [0, 0.001]; end t.value.should == 5 end - platform_is_not :darwin do - it "sleeps with nanosecond precision" do - start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - 100.times do - sleep(0.0001) - end - end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - - actual_duration = end_time - start_time - (actual_duration > 0.01).should == true # 100 * 0.0001 => 0.01 - (actual_duration < 0.03).should == true + it "sleeps with nanosecond precision" do + start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 100.times do + sleep(0.0001) end + end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + actual_duration = end_time - start_time + actual_duration.should > 0.01 # 100 * 0.0001 => 0.01 end ruby_version_is ""..."3.3" do