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.
This commit is contained in:
Brian Warner 2016-03-01 16:57:57 -08:00
parent 3fc3a563bf
commit b1dae14e6d

View File

@ -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()