mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fix a thread test.
* Use Queue for synchronization. * Don't use `sleep 0.2` and use `th.join` because created thread can raise an exception after 0.2 seconds.
This commit is contained in:
parent
fa1bf8ab37
commit
cf59e1476d
1 changed files with 7 additions and 7 deletions
|
@ -795,14 +795,15 @@ class TestThread < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_interrupt_blocking
|
def test_handle_interrupt_blocking
|
||||||
r=:ng
|
r = nil
|
||||||
e=Class.new(Exception)
|
q = Queue.new
|
||||||
|
e = Class.new(Exception)
|
||||||
th_s = Thread.current
|
th_s = Thread.current
|
||||||
th = Thread.start{
|
th = Thread.start {
|
||||||
assert_raise(RuntimeError) {
|
assert_raise(RuntimeError) {
|
||||||
Thread.handle_interrupt(Object => :on_blocking){
|
Thread.handle_interrupt(Object => :on_blocking){
|
||||||
begin
|
begin
|
||||||
Thread.pass until r == :wait
|
q.pop
|
||||||
Thread.current.raise RuntimeError, "will raise in sleep"
|
Thread.current.raise RuntimeError, "will raise in sleep"
|
||||||
r = :ok
|
r = :ok
|
||||||
sleep
|
sleep
|
||||||
|
@ -812,9 +813,8 @@ class TestThread < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_raise(e) {r = :wait; sleep 0.2}
|
assert_raise(e) {q << true; th.join}
|
||||||
th.join
|
assert_equal(:ok, r)
|
||||||
assert_equal(:ok,r)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_interrupt_and_io
|
def test_handle_interrupt_and_io
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue