let tests override KEY_TIMER/VERIFY_TIMER to tolerate slow test hosts

I've seen intermittent failures in
test_cli.PregeneratedCode.test_text_subprocess where the host was slow (or
overloaded) enough that the "Waiting for sender.." pacifier message was
displayed, which flunks the test because we're looking for a specific output
string. We patch this 1-second timer in the non-subprocess tests, but you
can't patch across a process boundary.

This patch adds an undocumented environment variable that lets you override
the timer values. The test then sets it to something large.

For future consideration: another approach would be to change the test to
tolerate the extra message. This would be trickier to validate, though.
This commit is contained in:
Brian Warner 2018-02-20 18:14:57 -08:00
parent e4e8216d2c
commit d42ac47ac8
3 changed files with 14 additions and 5 deletions

View File

@ -14,8 +14,8 @@ from .welcome import handle_welcome
APPID = u"lothar.com/wormhole/text-or-file-xfer" APPID = u"lothar.com/wormhole/text-or-file-xfer"
KEY_TIMER = 1.0 KEY_TIMER = float(os.environ.get("_MAGIC_WORMHOLE_TEST_KEY_TIMER", 1.0))
VERIFY_TIMER = 1.0 VERIFY_TIMER = float(os.environ.get("_MAGIC_WORMHOLE_TEST_VERIFY_TIMER", 1.0))
class RespondError(Exception): class RespondError(Exception):
def __init__(self, response): def __init__(self, response):

View File

@ -13,7 +13,7 @@ from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr
from .welcome import handle_welcome from .welcome import handle_welcome
APPID = u"lothar.com/wormhole/text-or-file-xfer" APPID = u"lothar.com/wormhole/text-or-file-xfer"
VERIFY_TIMER = 1 VERIFY_TIMER = float(os.environ.get("_MAGIC_WORMHOLE_TEST_VERIFY_TIMER", 1.0))
def send(args, reactor=reactor): def send(args, reactor=reactor):
"""I implement 'wormhole send'. I return a Deferred that fires with None """I implement 'wormhole send'. I return a Deferred that fires with None

View File

@ -468,6 +468,15 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
elif send_cfg.what: elif send_cfg.what:
content_args = [send_cfg.what] content_args = [send_cfg.what]
# raise the rx KEY_TIMER to some large number here, to avoid
# spurious test failures on hosts that are slow enough to trigger
# the "Waiting for sender..." pacifier message. We can do in
# not-as_subprocess, because we can directly patch the value before
# running the receiver. But we can't patch across the subprocess
# boundary, so we use an environment variable.
env = self._env.copy()
env["_MAGIC_WORMHOLE_TEST_KEY_TIMER"] = "999999"
env["_MAGIC_WORMHOLE_TEST_VERIFY_TIMER"] = "999999"
send_args = [ send_args = [
'--relay-url', self.relayurl, '--relay-url', self.relayurl,
'--transit-helper', '', '--transit-helper', '',
@ -479,7 +488,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
send_d = getProcessOutputAndValue( send_d = getProcessOutputAndValue(
wormhole_bin, send_args, wormhole_bin, send_args,
path=send_dir, path=send_dir,
env=self._env, env=env,
) )
recv_args = [ recv_args = [
'--relay-url', self.relayurl, '--relay-url', self.relayurl,
@ -495,7 +504,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
receive_d = getProcessOutputAndValue( receive_d = getProcessOutputAndValue(
wormhole_bin, recv_args, wormhole_bin, recv_args,
path=receive_dir, path=receive_dir,
env=self._env, env=env,
) )
(send_res, receive_res) = yield gatherResults([send_d, receive_d], (send_res, receive_res) = yield gatherResults([send_d, receive_d],