test_bignum.rb: refine test

* test/ruby/test_bignum.rb (test_interrupt_during_to_s): rename and
  merge with assert_interrupt, separate Bignum power from to_s, get
  rid of busy loop, and skip if the conversion is too fast.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-03-16 14:48:35 +00:00
parent de9911f597
commit 090a6ca4e9

View File

@ -560,27 +560,24 @@ class TestBignum < Test::Unit::TestCase
assert_equal(true, (2**32).even?)
end
def assert_interrupt
def test_interrupt_during_to_s
time = Time.now
start_flag = false
end_flag = false
num = (65536 ** 65536)
thread = Thread.new do
start_flag = true
yield
num.to_s
end_flag = true
end
Thread.pass until start_flag
sleep 0.001 until start_flag
thread.raise
thread.join rescue nil
time = Time.now - time
assert_equal([true, false], [start_flag, end_flag])
skip "too fast cpu" if end_flag
assert_operator(time, :<, 10)
end
def test_interrupt
assert_interrupt {(65536 ** 65536).to_s}
end
def test_interrupt_during_bigdivrem
return unless Process.respond_to?(:kill)
begin