Created
June 7, 2009 22:45
-
-
Save darrenboyd/125523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'timeout' | |
def test_timeout(timeout_timeout, count, &block) | |
pass = timeout = error = 0 | |
count.times do |i| | |
begin | |
Timeout::timeout(timeout_timeout, &block) | |
pass += 1 | |
rescue Timeout::Error => e | |
timeout += 1 | |
rescue Timeout::ExitException => e | |
error += 1 | |
end | |
end | |
[pass, timeout, error] | |
end | |
# With JRuby version 1.3, I started seeing odd errors from | |
# Timeout::timeout. The output from this little app was | |
# inconsistent. It would usually pass 90-95% of the time. | |
# | |
# I played around with setting the timeout value (0.9999 | |
# below) to 1. After that, I could no longer get anything | |
# but 'pass' from this test for any value. | |
# | |
puts "Simple quick loop test..." | |
pass, timeout, error = test_timeout(0.9999, 1000) { 1.times { |i| i }; true } | |
puts "Pass: #{pass}" | |
puts "Timeout: #{timeout}" | |
puts "Error: #{error}" | |
puts "Simply return true test..." | |
pass, timeout, error = test_timeout(0.9999, 1000) { true } | |
puts "Pass: #{pass}" | |
puts "Timeout: #{timeout}" | |
puts "Error: #{error}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment