summaryrefslogtreecommitdiff
path: root/test/test_prime.rb
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-18 00:55:34 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-18 00:55:34 +0000
commitc0b42eedeafd49c867ffd776d95a6aeb1d7b732a (patch)
tree16d7024103a08c2c3322eb1dd66dfb36a8740a98 /test/test_prime.rb
parent79a8955f8d99d6e603a90a8038da461687d275ec (diff)
* test/test_prime.rb
(TestPrime#test_eratosthenes_works_fine_after_timeout): test for [ruby-dev:39465]. * lib/prime.rb (Prime::EratosthenesSieve): fixed [ruby-dev:39465]. suppressed memory reallocation. constantified some magic numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_prime.rb')
-rw-r--r--test/test_prime.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_prime.rb b/test/test_prime.rb
index 307d53afb3..b4962bafcf 100644
--- a/test/test_prime.rb
+++ b/test/test_prime.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'prime'
require 'stringio'
+require 'timeout'
class TestPrime < Test::Unit::TestCase
# The first 100 prime numbers
@@ -143,4 +144,29 @@ class TestPrime < Test::Unit::TestCase
assert !-4.prime?
end
end
+
+ def test_eratosthenes_works_fine_after_timeout
+ sieve = Prime::EratosthenesSieve.instance
+ sieve.send(:initialize)
+ begin
+ # simulates that Timeout.timeout interrupts Prime::EratosthenesSieve#extend_table
+ def sieve.Integer(n)
+ n = super(n)
+ sleep 10 if /extend_table/ =~ caller.first
+ return n
+ end
+
+ begin
+ Timeout.timeout(0.5) { Prime.each(7*37){} }
+ flunk("timeout expected")
+ rescue Timeout::Error
+ end
+ ensure
+ class << sieve
+ remove_method :Integer
+ end
+ end
+
+ refute_includes Prime.each(7*37).to_a, 7*37, "[ruby-dev:39465]"
+ end
end