Moved slow connection notification to stderr
added test for slow connection notifications
This commit is contained in:
parent
01318d1130
commit
6bdaaf368c
|
@ -12,6 +12,7 @@ from ..util import (dict_to_bytes, bytes_to_dict, bytes_to_hexstr,
|
||||||
estimate_free_space)
|
estimate_free_space)
|
||||||
|
|
||||||
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
||||||
|
VERIFY_TIMER = 1
|
||||||
|
|
||||||
class RespondError(Exception):
|
class RespondError(Exception):
|
||||||
def __init__(self, response):
|
def __init__(self, response):
|
||||||
|
@ -78,8 +79,8 @@ class TwistedReceiver:
|
||||||
yield w.establish_key()
|
yield w.establish_key()
|
||||||
def on_slow_connection():
|
def on_slow_connection():
|
||||||
print(u"Key established, waiting for confirmation...",
|
print(u"Key established, waiting for confirmation...",
|
||||||
file=self.args.stdout)
|
file=self.args.stderr)
|
||||||
notify = self._reactor.callLater(1, on_slow_connection)
|
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
|
||||||
try:
|
try:
|
||||||
verifier = yield w.verify()
|
verifier = yield w.verify()
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -12,6 +12,7 @@ from ..transit import TransitSender
|
||||||
from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr
|
from ..util import dict_to_bytes, bytes_to_dict, bytes_to_hexstr
|
||||||
|
|
||||||
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
APPID = u"lothar.com/wormhole/text-or-file-xfer"
|
||||||
|
VERIFY_TIMER = 1
|
||||||
|
|
||||||
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
|
||||||
|
@ -88,8 +89,8 @@ class Sender:
|
||||||
yield w.establish_key()
|
yield w.establish_key()
|
||||||
def on_slow_connection():
|
def on_slow_connection():
|
||||||
print(u"Key established, waiting for confirmation...",
|
print(u"Key established, waiting for confirmation...",
|
||||||
file=args.stdout)
|
file=args.stderr)
|
||||||
notify = self._reactor.callLater(1, on_slow_connection)
|
notify = self._reactor.callLater(VERIFY_TIMER, on_slow_connection)
|
||||||
|
|
||||||
# TODO: don't stall on w.verify() unless they want it
|
# TODO: don't stall on w.verify() unless they want it
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -225,9 +225,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def _do_test(self, as_subprocess=False,
|
def _do_test(self, as_subprocess=False,
|
||||||
mode="text", addslash=False, override_filename=False):
|
mode="text", addslash=False, override_filename=False):
|
||||||
assert mode in ("text", "file", "directory")
|
assert mode in ("text", "file", "directory", "slow")
|
||||||
send_cfg = config("send")
|
send_cfg = Config()
|
||||||
recv_cfg = config("receive")
|
recv_cfg = Config()
|
||||||
message = "blah blah blah ponies"
|
message = "blah blah blah ponies"
|
||||||
|
|
||||||
for cfg in [send_cfg, recv_cfg]:
|
for cfg in [send_cfg, recv_cfg]:
|
||||||
|
@ -244,7 +244,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
receive_dir = self.mktemp()
|
receive_dir = self.mktemp()
|
||||||
os.mkdir(receive_dir)
|
os.mkdir(receive_dir)
|
||||||
|
|
||||||
if mode == "text":
|
if mode == "text" or mode == "slow":
|
||||||
send_cfg.text = message
|
send_cfg.text = message
|
||||||
|
|
||||||
elif mode == "file":
|
elif mode == "file":
|
||||||
|
@ -348,8 +348,14 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
|
|
||||||
# The sender might fail, leaving the receiver hanging, or vice
|
# The sender might fail, leaving the receiver hanging, or vice
|
||||||
# versa. Make sure we don't wait on one side exclusively
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
yield gatherResults([send_d, receive_d], True)
|
|
||||||
send_stdout = send_cfg.stdout.getvalue()
|
send_stdout = send_cfg.stdout.getvalue()
|
||||||
send_stderr = send_cfg.stderr.getvalue()
|
send_stderr = send_cfg.stderr.getvalue()
|
||||||
receive_stdout = recv_cfg.stdout.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
|
self.maxDiff = None # show full output for assertion failures
|
||||||
|
|
||||||
self.failUnlessEqual(send_stderr, "",
|
if mode != "slow":
|
||||||
(send_stdout, send_stderr))
|
self.failUnlessEqual(send_stderr, "",
|
||||||
self.failUnlessEqual(receive_stderr, "",
|
(send_stdout, send_stderr))
|
||||||
(receive_stdout, receive_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
|
# check sender
|
||||||
if mode == "text":
|
if mode == "text" or mode == "slow":
|
||||||
expected = ("Sending text message ({bytes:d} Bytes){NL}"
|
expected = ("Sending text message ({bytes:d} Bytes){NL}"
|
||||||
"On the other computer, please run: "
|
"On the other computer, please run: "
|
||||||
"wormhole receive{NL}"
|
"wormhole receive{NL}"
|
||||||
|
@ -401,7 +415,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
.format(NL=NL), send_stdout)
|
.format(NL=NL), send_stdout)
|
||||||
|
|
||||||
# check receiver
|
# check receiver
|
||||||
if mode == "text":
|
if mode == "text" or mode == "slow":
|
||||||
self.failUnlessEqual(receive_stdout, message+NL)
|
self.failUnlessEqual(receive_stdout, message+NL)
|
||||||
elif mode == "file":
|
elif mode == "file":
|
||||||
self.failUnlessIn("Receiving file ({size:s}) into: {name}"
|
self.failUnlessIn("Receiving file ({size:s}) into: {name}"
|
||||||
|
@ -448,6 +462,9 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
|
||||||
def test_directory_override(self):
|
def test_directory_override(self):
|
||||||
return self._do_test(mode="directory", override_filename=True)
|
return self._do_test(mode="directory", override_filename=True)
|
||||||
|
|
||||||
|
def test_slow(self):
|
||||||
|
return self._do_test(mode="slow")
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def _do_test_fail(self, mode, failmode):
|
def _do_test_fail(self, mode, failmode):
|
||||||
assert mode in ("file", "directory")
|
assert mode in ("file", "directory")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user