From b1dae14e6d26882451e4aee80fc4412fb64674f5 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 1 Mar 2016 16:57:57 -0800 Subject: [PATCH] test_scripts: handle hangs in one client When test_scripts ran two clients at the same time, an error in one could leave the other hanging (in a thread). One Deferred would errback, the other would hang. Tests wait on one Deferred at a time, so if we're unlucky and were waiting on the hanging Deferred (instead of the erroring one), we'll wait forever, or at least until the default test timeout of 180 seconds. This adds an errback to notice when either client has errored, and cancels the other Deferred, so it doesn't matter which one we wait upon first. --- src/wormhole/test/test_scripts.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index 2d31dc7..3ecd9dc 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -308,6 +308,18 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): else: receive_d = deferToThread(cmd_receive_blocking.receive_blocking, rargs) + # The sender might fail, leaving the receiver hanging, or vice + # versa. If either side fails, cancel the other, so it won't + # matter which Deferred we wait upon first. + + def _oops(f, which): + log.msg("test_scripts: %s failed, cancelling both" % which) + send_d.cancel() + receive_d.cancel() + return f + send_d.addErrback(_oops, "send_d") + receive_d.addErrback(_oops, "receive_d") + send_rc = yield send_d send_stdout = sargs.stdout.getvalue() send_stderr = sargs.stderr.getvalue()