From 547ead75baaeb8452a84967f799d89215856a30d Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 12 Feb 2018 16:52:10 -0800 Subject: [PATCH] test_transit_server: factor out wait() --- .../test/test_transit_server.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/wormhole_transit_relay/test/test_transit_server.py b/src/wormhole_transit_relay/test/test_transit_server.py index 10755ca..8ce4a93 100644 --- a/src/wormhole_transit_relay/test/test_transit_server.py +++ b/src/wormhole_transit_relay/test/test_transit_server.py @@ -31,6 +31,11 @@ class Accumulator(protocol.Protocol): self._wait.errback(RuntimeError("closed")) self._disconnect.callback(None) +def wait(): + d = defer.Deferred() + reactor.callLater(0.001, d.callback, None) + return d + class _Transit: def test_blur_size(self): blur = transit_server.blur_size @@ -62,14 +67,14 @@ class _Transit: # let that arrive while self.count() == 0: - yield self.wait() + yield wait() self.assertEqual(self.count(), 1) a1.transport.loseConnection() # let that get removed while self.count() > 0: - yield self.wait() + yield wait() self.assertEqual(self.count(), 0) # the token should be removed too @@ -203,10 +208,6 @@ class _Transit: return sum([len(potentials) for potentials in self._transit_server._pending_requests.values()]) - def wait(self): - d = defer.Deferred() - reactor.callLater(0.001, d.callback, None) - return d @defer.inlineCallbacks def test_ignore_same_side(self): @@ -220,12 +221,12 @@ class _Transit: b" for side " + hexlify(side1) + b"\n") # let that arrive while self.count() == 0: - yield self.wait() + yield wait() a2.transport.write(b"please relay " + hexlify(token1) + b" for side " + hexlify(side1) + b"\n") # let that arrive while self.count() == 1: - yield self.wait() + yield wait() self.assertEqual(self.count(), 2) # same-side connections don't match a1.transport.loseConnection()