post-rebase: update newer tests

This commit is contained in:
Brian Warner 2020-05-23 17:50:26 -07:00
parent 45824ca5d6
commit ca309d5283

View File

@ -1,15 +1,9 @@
from __future__ import print_function, unicode_literals
from binascii import hexlify
from twisted.trial import unittest
from twisted.internet import reactor, defer
from .common import ServerBase
from .. import transit_server
def wait():
d = defer.Deferred()
reactor.callLater(0.001, d.callback, None)
return d
def handshake(token, side=None):
hs = b"please relay " + hexlify(token)
if side is not None:
@ -296,22 +290,16 @@ class _Transit:
p1.transport.loseConnection()
@defer.inlineCallbacks
def test_short_handshake(self):
ep = clientFromString(reactor, self.transit)
a1 = yield connectProtocol(ep, Accumulator())
p1 = self.new_protocol()
# hang up before sending a complete handshake
a1.transport.write(b"short")
a1.transport.loseConnection()
p1.dataReceived(b"short")
p1.transport.loseConnection()
@defer.inlineCallbacks
def test_empty_handshake(self):
ep = clientFromString(reactor, self.transit)
a1 = yield connectProtocol(ep, Accumulator())
p1 = self.new_protocol()
# hang up before sending anything
a1.transport.loseConnection()
p1.transport.loseConnection()
class TransitWithLogs(_Transit, ServerBase, unittest.TestCase):
log_requests = True
@ -328,46 +316,27 @@ class Usage(ServerBase, unittest.TestCase):
total_time, waiting_time))
self._transit_server.recordUsage = record
@defer.inlineCallbacks
def test_empty(self):
ep = clientFromString(reactor, self.transit)
a1 = yield connectProtocol(ep, Accumulator())
p1 = self.new_protocol()
# hang up before sending anything
a1.transport.loseConnection()
yield a1._disconnect
# give the server a chance to react. in most of the other tests, the
# server hangs up on us, so this test needs extra synchronization
while len(self._usage) == 0:
d = defer.Deferred()
reactor.callLater(0.01, d.callback, None)
yield d
p1.transport.loseConnection()
# that will log the "empty" usage event
self.assertEqual(len(self._usage), 1, self._usage)
(started, result, total_bytes, total_time, waiting_time) = self._usage[0]
self.assertEqual(result, "empty", self._usage)
@defer.inlineCallbacks
def test_short(self):
ep = clientFromString(reactor, self.transit)
a1 = yield connectProtocol(ep, Accumulator())
p1 = self.new_protocol()
# hang up before sending a complete handshake
a1.transport.write(b"short")
a1.transport.loseConnection()
yield a1._disconnect
# give the server a chance to react. in most of the other tests, the
# server hangs up on us, so this test needs extra synchronization
while len(self._usage) == 0:
d = defer.Deferred()
reactor.callLater(0.01, d.callback, None)
yield d
p1.transport.write(b"short")
p1.transport.loseConnection()
# that will log the "empty" usage event
self.assertEqual(len(self._usage), 1, self._usage)
(started, result, total_bytes, total_time, waiting_time) = self._usage[0]
self.assertEqual(result, "empty", self._usage)
@defer.inlineCallbacks
def test_errory(self):
p1 = self.new_protocol()