Thursday, October 16, 2008

Timeout::TimeoutError

This was annoying
def test_timeout_error
Timeout.expects(:timeout).with(any_parameters).raises(Timeout::Error.new)
assert_raise(Timeout::Error) {
some_crazy_code()
}
end


1) Error:
test_timeout_error(TimerTest):
ArgumentError: wrong number of arguments (0 for 1)

Here is the fix!
def test_timeout_error
Timeout.expects(:timeout).with(any_parameters).raises(Timeout::Error)
assert_raise(Timeout::Error) {
some_crazy_code()
}
end


UPDATE: WARNING WARNING WARNING
Do not use Timeout::timeout in Ruby 1.8! IT DOES NOT WORK RIGHT!
http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html
http://ph7spot.com/articles/system_timer
http://www.mikeperham.com/2009/03/15/socket-timeouts-in-ruby/

No comments: