From 89819fae96822d0aff04fc53b4521470efcdf8f5 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 4 Sep 2017 17:32:38 +0200 Subject: [PATCH] Test SeattleTestbed/repy_v2#52, socket timeout This patches `emulcomm` to provide some insight into the mechanics of too-large socket timeouts, and provides a unit test to trigger the instrumentation. --- emulcomm.py | 3 +++ ...ut_repyv2api_openconnectionhugetimeout.r2py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 testsV2/ut_repyv2api_openconnectionhugetimeout.r2py diff --git a/emulcomm.py b/emulcomm.py index 96b26961..dac668ba 100755 --- a/emulcomm.py +++ b/emulcomm.py @@ -1162,6 +1162,7 @@ def _timed_conn_initialize(localip,localport,destip,destport, timeout): # Get a TCP socket bound to the local ip / port sock = _get_tcp_socket(localip, localport) sock.settimeout(timeout) + print "Set the socket timeout to", sock.gettimeout() try: # Try to connect until we timeout @@ -1169,9 +1170,11 @@ def _timed_conn_initialize(localip,localport,destip,destport, timeout): while nonportable.getruntime() - starttime < timeout: try: sock.connect((destip, destport)) + print nonportable.getruntime(), "This should never print" connected = True break except Exception, e: + print nonportable.getruntime(), "Exception is", repr(e) # Check if we are already connected if _is_already_connected_exception(e): connected = True diff --git a/testsV2/ut_repyv2api_openconnectionhugetimeout.r2py b/testsV2/ut_repyv2api_openconnectionhugetimeout.r2py new file mode 100644 index 00000000..06c8bc3d --- /dev/null +++ b/testsV2/ut_repyv2api_openconnectionhugetimeout.r2py @@ -0,0 +1,18 @@ +""" +Test for SeattleTestbed/repy_v2#52, openconnection timeout issues +""" +timeout = 100 +start_time = getruntime() +log("Timeout", timeout, "Start time:", str(start_time), "\n") + +try: + openconnection(gethostbyname("gmail.com"), 63100, getmyip(), 63100, timeout) +except TimeoutError: + pass +except Exception, e: + log(getruntime(), "Error raised: ", repr(e)) + +end_time = getruntime() +log("End time: " + str(end_time)) +log("Elapsed time: " + str(end_time - start_time)) +log("\n")