ruby-changes:34115
From: nobu <ko1@a...>
Date: Wed, 28 May 2014 12:05:56 +0900 (JST)
Subject: [ruby-changes:34115] nobu:r46196 (trunk): test_thread.rb: move thread switch test
nobu 2014-05-28 12:05:48 +0900 (Wed, 28 May 2014) New Revision: 46196 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46196 Log: test_thread.rb: move thread switch test * test/ruby/test_thread.rb (test_switch_while_busy_loop): move from test/test_timeout.rb. [Bug #1402] * test/test_timeout.rb (test_timeout): no longer related to [Bug #1402]. [Bug #8523] Modified files: trunk/test/ruby/test_thread.rb trunk/test/test_timeout.rb Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 46195) +++ test/ruby/test_thread.rb (revision 46196) @@ -369,6 +369,24 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L369 c.kill if c end + def test_switch_while_busy_loop + bug1402 = "[ruby-dev:38319] [Bug #1402]" + flag = true + th = Thread.current + waiter = Thread.start { + sleep 0.1 + flag = false + sleep 1 + th.raise(bug1402) + } + assert_nothing_raised(RuntimeError, bug1402) do + nil while flag + end + assert(!flag, bug1402) + ensure + waiter.kill.join + end + def test_safe_level ok = false t = Thread.new do Index: test/test_timeout.rb =================================================================== --- test/test_timeout.rb (revision 46195) +++ test/test_timeout.rb (revision 46196) @@ -11,17 +11,11 @@ class TestTimeout < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_timeout.rb#L11 end def test_timeout - flag = true - Thread.start { - sleep 1 - flag = false - } - assert_raise(Timeout::Error, "[ruby-dev:38319]") do + assert_raise(Timeout::Error) do Timeout.timeout(0.1) { - Thread.pass while flag + nil while true } end - assert flag, "[ruby-dev:38319]" end def test_cannot_convert_into_time_interval -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/