mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_thread.rb: stop at once
* test/ruby/test_thread.rb (test_priority): stop both threads at once by a flag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e9bb3b9d30
commit
2c3522c3e4
1 changed files with 6 additions and 2 deletions
|
@ -127,17 +127,21 @@ class TestThread < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_priority
|
def test_priority
|
||||||
c1 = c2 = 0
|
c1 = c2 = 0
|
||||||
t1 = Thread.new { loop { c1 += 1 } }
|
run = true
|
||||||
|
t1 = Thread.new { c1 += 1 while run }
|
||||||
t1.priority = 3
|
t1.priority = 3
|
||||||
t2 = Thread.new { loop { c2 += 1 } }
|
t2 = Thread.new { c2 += 1 while run }
|
||||||
t2.priority = -3
|
t2.priority = -3
|
||||||
assert_equal(3, t1.priority)
|
assert_equal(3, t1.priority)
|
||||||
assert_equal(-3, t2.priority)
|
assert_equal(-3, t2.priority)
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
5.times do
|
5.times do
|
||||||
|
assert_not_predicate(t1, :stop?)
|
||||||
|
assert_not_predicate(t2, :stop?)
|
||||||
break if c1 > c2
|
break if c1 > c2
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
|
run = false
|
||||||
t1.kill
|
t1.kill
|
||||||
t2.kill
|
t2.kill
|
||||||
assert_operator(c1, :>, c2, "[ruby-dev:33124]") # not guaranteed
|
assert_operator(c1, :>, c2, "[ruby-dev:33124]") # not guaranteed
|
||||||
|
|
Loading…
Reference in a new issue