Skip to content

Commit

Permalink
Move sleep ns precision spec to kernel and omit darwin
Browse files Browse the repository at this point in the history
This is really a sleep spec, so it should be tested under the
Kernel#sleep specs.

Fails consistently on MacOS (in CI) and passes consistently on
Linux and Windows so omit MacOS for now.
  • Loading branch information
headius committed Nov 6, 2024
1 parent 1474df8 commit 3cc8136
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 14 additions & 0 deletions core/kernel/sleep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ 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
end
end

ruby_version_is ""..."3.3" do
it "raises a TypeError when passed nil" do
-> { sleep(nil) }.should raise_error(TypeError)
Expand Down
12 changes: 0 additions & 12 deletions core/thread/wakeup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,4 @@

describe "Thread#wakeup" do
it_behaves_like :thread_wakeup, :wakeup

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
end
end

0 comments on commit 3cc8136

Please sign in to comment.