Moved slow connection notification to stderr

added test for slow connection notifications
This commit is contained in:
laharah 2016-06-17 22:03:58 -07:00 committed by Brian Warner
parent 01318d1130
commit 6bdaaf368c
3 changed files with 34 additions and 15 deletions

View File

@ -12,6 +12,7 @@ from ..util import (dict_to_bytes, bytes_to_dict, bytes_to_hexstr,
estimate_free_space)
APPID = u"lothar.com/wormhole/text-or-file-xfer"
VERIFY_TIMER = 1
class RespondError(Exception):
def __init__(self, response):
@ -78,8 +79,8 @@ class TwistedReceiver:
yield w.establish_key()
def on_slow_connection():
print(u"Key established, waiting for confirmation...",
file=self.args.stdout)
notify = self._reactor.callLater(1, on_slow_connection)
file=self.args.stderr)
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
try:
verifier = yield w.verify()
finally:

View File

@ -12,6 +12,7 @@ from ..transit import TransitSender
from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr
APPID = u"lothar.com/wormhole/text-or-file-xfer"
VERIFY_TIMER = 1
def send(args, reactor=reactor):
"""I implement 'wormhole send'. I return a Deferred that fires with None
@ -88,8 +89,8 @@ class Sender:
yield w.establish_key()
def on_slow_connection():
print(u"Key established, waiting for confirmation...",
file=args.stdout)
notify = self._reactor.callLater(1, on_slow_connection)
file=args.stderr)
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
# TODO: don't stall on w.verify() unless they want it
try:

View File

@ -225,9 +225,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
@inlineCallbacks
def _do_test(self, as_subprocess=False,
mode="text", addslash=False, override_filename=False):
assert mode in ("text", "file", "directory")
send_cfg = config("send")
recv_cfg = config("receive")
assert mode in ("text", "file", "directory", "slow")
send_cfg = Config()
recv_cfg = Config()
message = "blah blah blah ponies"
for cfg in [send_cfg, recv_cfg]:
@ -244,7 +244,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
receive_dir = self.mktemp()
os.mkdir(receive_dir)
if mode == "text":
if mode == "text" or mode == "slow":
send_cfg.text = message
elif mode == "file":
@ -348,8 +348,14 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
# The sender might fail, leaving the receiver hanging, or vice
# versa. Make sure we don't wait on one side exclusively
if mode == "slow":
with mock.patch.object(cmd_send, "VERIFY_TIMER", 0), \
mock.patch.object(cmd_receive, "VERIFY_TIMER", 0):
yield gatherResults([send_d, receive_d], True)
else:
yield gatherResults([send_d, receive_d], True)
send_stdout = send_cfg.stdout.getvalue()
send_stderr = send_cfg.stderr.getvalue()
receive_stdout = recv_cfg.stdout.getvalue()
@ -361,13 +367,21 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
self.maxDiff = None # show full output for assertion failures
if mode != "slow":
self.failUnlessEqual(send_stderr, "",
(send_stdout, send_stderr))
self.failUnlessEqual(receive_stderr, "",
(receive_stdout, receive_stderr))
else:
self.assertEqual(send_stderr,
"Key established, waiting for confirmation...\n",
(send_stdout, send_stderr))
self.assertEqual(receive_stderr,
"Key established, waiting for confirmation...\n",
(receive_stdout, receive_stderr))
# check sender
if mode == "text":
if mode == "text" or mode == "slow":
expected = ("Sending text message ({bytes:d} Bytes){NL}"
"On the other computer, please run: "
"wormhole receive{NL}"
@ -401,7 +415,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
.format(NL=NL), send_stdout)
# check receiver
if mode == "text":
if mode == "text" or mode == "slow":
self.failUnlessEqual(receive_stdout, message+NL)
elif mode == "file":
self.failUnlessIn("Receiving file ({size:s}) into: {name}"
@ -448,6 +462,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
def test_directory_override(self):
return self._do_test(mode="directory", override_filename=True)
def test_slow(self):
return self._do_test(mode="slow")
@inlineCallbacks
def _do_test_fail(self, mode, failmode):
assert mode in ("file", "directory")