ruby-changes:59364
From: Koichi <ko1@a...>
Date: Sun, 22 Dec 2019 06:30:43 +0900 (JST)
Subject: [ruby-changes:59364] cf59e1476d (master): fix a thread test.
https://git.ruby-lang.org/ruby.git/commit/?id=cf59e1476d From cf59e1476d01be27dc88cbee5f6c6cf87f007043 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Sun, 22 Dec 2019 06:28:13 +0900 Subject: 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. diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index bf61a28..f8127d8 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -795,14 +795,15 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L795 end def test_handle_interrupt_blocking - r=:ng - e=Class.new(Exception) + r = nil + q = Queue.new + e = Class.new(Exception) th_s = Thread.current - th = Thread.start{ + th = Thread.start { assert_raise(RuntimeError) { Thread.handle_interrupt(Object => :on_blocking){ begin - Thread.pass until r == :wait + q.pop Thread.current.raise RuntimeError, "will raise in sleep" r = :ok sleep @@ -812,9 +813,8 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L813 } } } - assert_raise(e) {r = :wait; sleep 0.2} - th.join - assert_equal(:ok,r) + assert_raise(e) {q << true; th.join} + assert_equal(:ok, r) end def test_handle_interrupt_and_io -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/