P
Pat Maddox
I'm writing a little method that just tries to open a tcp socket
connection, then closes it off. I'm using timeout to limit the amount
of time it tries to connect (is there a better way?). If it times
out, I just want to say that the connect failed. Despite catching the
Timeout::Error (I think, anyway), I always get the Exception output.
First, here's the method:
def execute
status = timeout(@timeoutval) {
socket = TCPSocket.new(@host, @port) rescue false
socket.close if socket
return socket != false
} rescue Timeout::Error
return false
end
And now the output from my unit test:
Started
/usr/local/lib/ruby/1.8/timeout.rb:42:in `new': execution expired
(Timeout::Error)
from ./PortHostTest.rb:16:in `execute'
from ./PortHostTest.rb:15:in `timeout'
from /usr/local/lib/ruby/1.8/timeout.rb:55:in `timeout'
from ./PortHostTest.rb:15:in `execute'
from ./HostTest.rb:10:in `runTest'
from ../tests/test_HostTest.rb:14:in `test_simple'
from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:70:in `__send__'
from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:70:in `run'
... 10 levels...
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:194:in `run'
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:14:in `run'
from /usr/local/lib/ruby/1.8/test/unit.rb:285
from /usr/local/lib/ruby/1.8/test/unit.rb:283
connection, then closes it off. I'm using timeout to limit the amount
of time it tries to connect (is there a better way?). If it times
out, I just want to say that the connect failed. Despite catching the
Timeout::Error (I think, anyway), I always get the Exception output.
First, here's the method:
def execute
status = timeout(@timeoutval) {
socket = TCPSocket.new(@host, @port) rescue false
socket.close if socket
return socket != false
} rescue Timeout::Error
return false
end
And now the output from my unit test:
Started
/usr/local/lib/ruby/1.8/timeout.rb:42:in `new': execution expired
(Timeout::Error)
from ./PortHostTest.rb:16:in `execute'
from ./PortHostTest.rb:15:in `timeout'
from /usr/local/lib/ruby/1.8/timeout.rb:55:in `timeout'
from ./PortHostTest.rb:15:in `execute'
from ./HostTest.rb:10:in `runTest'
from ../tests/test_HostTest.rb:14:in `test_simple'
from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:70:in `__send__'
from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:70:in `run'
... 10 levels...
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:194:in `run'
from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:14:in `run'
from /usr/local/lib/ruby/1.8/test/unit.rb:285
from /usr/local/lib/ruby/1.8/test/unit.rb:283