test_wormhole: fix message-doubling test

This commit is contained in:
Brian Warner 2017-03-04 12:44:07 +01:00
parent 105d9cc59f
commit 4234e79161

View File

@ -6,7 +6,7 @@ from twisted.trial import unittest
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet.defer import Deferred, gatherResults, inlineCallbacks from twisted.internet.defer import Deferred, gatherResults, inlineCallbacks
from .common import ServerBase from .common import ServerBase
from .. import wormhole from .. import wormhole, _order
from ..errors import (WrongPasswordError, WelcomeError, InternalError, from ..errors import (WrongPasswordError, WelcomeError, InternalError,
KeyFormatError) KeyFormatError)
from spake2 import SPAKE2_Symmetric from spake2 import SPAKE2_Symmetric
@ -924,9 +924,9 @@ class Wormholes(ServerBase, unittest.TestCase):
# SPAKE2.finish() to be called a second time, which throws an error # SPAKE2.finish() to be called a second time, which throws an error
# (which, being somewhat unexpected, caused a hang rather than a # (which, being somewhat unexpected, caused a hang rather than a
# clear exception). # clear exception).
with mock.patch("wormhole.wormhole._Wormhole", MessageDoublingReceiver): with mock.patch("wormhole.wormhole._order", MessageDoubler):
w1 = wormhole.wormhole(APPID, self.relayurl, reactor) w1 = wormhole.create(APPID, self.relayurl, reactor)
w2 = wormhole.wormhole(APPID, self.relayurl, reactor) w2 = wormhole.create(APPID, self.relayurl, reactor)
w1.set_code("123-purple-elephant") w1.set_code("123-purple-elephant")
w2.set_code("123-purple-elephant") w2.set_code("123-purple-elephant")
w1.send(b"data1"), w2.send(b"data2") w1.send(b"data1"), w2.send(b"data2")
@ -937,16 +937,16 @@ class Wormholes(ServerBase, unittest.TestCase):
yield w1.close() yield w1.close()
yield w2.close() yield w2.close()
class MessageDoublingReceiver(wormhole._Wormhole): class MessageDoubler(_order.Order):
# we could double messages on the sending side, but a future server will # we could double messages on the sending side, but a future server will
# strip those duplicates, so to really exercise the receiver, we must # strip those duplicates, so to really exercise the receiver, we must
# double them on the inbound side instead # double them on the inbound side instead
#def _msg_send(self, phase, body): #def _msg_send(self, phase, body):
# wormhole._Wormhole._msg_send(self, phase, body) # wormhole._Wormhole._msg_send(self, phase, body)
# self._ws_send_command("add", phase=phase, body=bytes_to_hexstr(body)) # self._ws_send_command("add", phase=phase, body=bytes_to_hexstr(body))
def _event_received_peer_message(self, side, phase, body): def got_message(self, side, phase, body):
wormhole._Wormhole._event_received_peer_message(self, side, phase, body) _order.Order.got_message(self, side, phase, body)
wormhole._Wormhole._event_received_peer_message(self, side, phase, body) _order.Order.got_message(self, side, phase, body)
class Errors(ServerBase, unittest.TestCase): class Errors(ServerBase, unittest.TestCase):
@inlineCallbacks @inlineCallbacks