diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 15:41:50 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 15:41:50 +0000 |
commit | 4d7b0b9112f2adf9e87ef75056f930bf7c1f3dc4 (patch) | |
tree | 8d712e18a619a9720d181d0d44e8cc2474ff31ee /spec/ruby/core/mutex | |
parent | 821d9a2d30f2e0d3f9009dc001b4b49aaa63c66e (diff) | |
download | ruby-4d7b0b9112f2adf9e87ef75056f930bf7c1f3dc4.tar.gz |
Update to ruby/spec@bacedc5
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/mutex')
-rw-r--r-- | spec/ruby/core/mutex/sleep_spec.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb index a3fb86fba7..ab49ccfd7d 100644 --- a/spec/ruby/core/mutex/sleep_spec.rb +++ b/spec/ruby/core/mutex/sleep_spec.rb @@ -25,9 +25,11 @@ describe "Mutex#sleep" do m = Mutex.new m.lock duration = 0.1 - start = Time.now + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) m.sleep duration - (Time.now - start).should be_close(duration, 0.2) + now = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (now - start).should > 0 + (now - start).should < 2.0 end it "unlocks the mutex while sleeping" do @@ -71,4 +73,23 @@ describe "Mutex#sleep" do m.lock m.sleep(0.01).should be_kind_of(Integer) end + + it "wakes up when requesting sleep times near or equal to zero" do + times = [] + val = 1 + + # power of two divisor so we eventually get near zero + loop do + val = val / 16.0 + times << val + break if val == 0.0 + end + + m = Mutex.new + m.lock + times.each do |time| + # just testing that sleep completes + m.sleep(time).should_not == nil + end + end end |