From d42ac47ac8d16cb1b71c9c2aa570d5589e346264 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 20 Feb 2018 18:14:57 -0800 Subject: [PATCH] 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. --- src/wormhole/cli/cmd_receive.py | 4 ++-- src/wormhole/cli/cmd_send.py | 2 +- src/wormhole/test/test_cli.py | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index aa7f3a2..1cb457b 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -14,8 +14,8 @@ from .welcome import handle_welcome APPID = u"lothar.com/wormhole/text-or-file-xfer" -KEY_TIMER = 1.0 -VERIFY_TIMER = 1.0 +KEY_TIMER = float(os.environ.get("_MAGIC_WORMHOLE_TEST_KEY_TIMER", 1.0)) +VERIFY_TIMER = float(os.environ.get("_MAGIC_WORMHOLE_TEST_VERIFY_TIMER", 1.0)) class RespondError(Exception): def __init__(self, response): diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 0e5c4e5..969ab0f 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -13,7 +13,7 @@ from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr from .welcome import handle_welcome 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): """I implement 'wormhole send'. I return a Deferred that fires with None diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index ca2d405..2ff080e 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -468,6 +468,15 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): elif 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 = [ '--relay-url', self.relayurl, '--transit-helper', '', @@ -479,7 +488,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): send_d = getProcessOutputAndValue( wormhole_bin, send_args, path=send_dir, - env=self._env, + env=env, ) recv_args = [ '--relay-url', self.relayurl, @@ -495,7 +504,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): receive_d = getProcessOutputAndValue( wormhole_bin, recv_args, path=receive_dir, - env=self._env, + env=env, ) (send_res, receive_res) = yield gatherResults([send_d, receive_d],