1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Distinguish signal and timeout [Bug #16608]

This commit is contained in:
Nobuyoshi Nakada 2020-02-06 09:14:40 +09:00 committed by Jeremy Evans
parent 8897098b5c
commit 070557afc4
Notes: git 2021-07-26 05:09:31 +09:00
5 changed files with 24 additions and 14 deletions

View file

@ -16,6 +16,7 @@ class TestThreadConditionVariable < Test::Unit::TestCase
mutex = Thread::Mutex.new
condvar = Thread::ConditionVariable.new
result = []
woken = nil
mutex.synchronize do
t = Thread.new do
mutex.synchronize do
@ -25,11 +26,12 @@ class TestThreadConditionVariable < Test::Unit::TestCase
end
result << 0
condvar.wait(mutex)
woken = condvar.wait(mutex)
result << 2
t.join
end
assert_equal([0, 1, 2], result)
assert(woken)
end
def test_condvar_wait_exception_handling
@ -140,11 +142,12 @@ INPUT
condvar = Thread::ConditionVariable.new
timeout = 0.3
locked = false
woken = true
t0 = Time.now
mutex.synchronize do
begin
condvar.wait(mutex, timeout)
woken = condvar.wait(mutex, timeout)
ensure
locked = mutex.locked?
end
@ -154,6 +157,7 @@ INPUT
assert_operator(timeout*0.9, :<, t)
assert(locked)
assert_nil(woken)
end
def test_condvar_nolock