Skip to content

Commit

Permalink
Merge pull request #2335 from herwinw/spec_kernel_sleep
Browse files Browse the repository at this point in the history
Refresh specs for Kernel.sleep
  • Loading branch information
seven1m authored Nov 14, 2024
2 parents 1dacb3d + 49a7143 commit 167e5ed
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions spec/core/kernel/sleep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 167e5ed

Please sign in to comment.