def test_full(self): eq = EventualQueue(reactor) w1 = wormhole.create(APPID, self.relayurl, reactor, _enable_dilate=True) w2 = wormhole.create(APPID, self.relayurl, reactor, _enable_dilate=True) w1.allocate_code() code = yield w1.get_code() print("code is: {}".format(code)) w2.set_code(code) yield doBoth(w1.get_verifier(), w2.get_verifier()) print("connected") eps1_d = w1.dilate() eps2_d = w2.dilate() (eps1, eps2) = yield doBoth(eps1_d, eps2_d) (control_ep1, connect_ep1, listen_ep1) = eps1 (control_ep2, connect_ep2, listen_ep2) = eps2 print("w.dilate ready") f1 = Factory() f1.protocol = L f1.d = Deferred() f1.d.addCallback(lambda data: eq.fire_eventually(data)) d1 = control_ep1.connect(f1) f2 = Factory() f2.protocol = L f2.d = Deferred() f2.d.addCallback(lambda data: eq.fire_eventually(data)) d2 = control_ep2.connect(f2) yield d1 yield d2 print("control endpoints connected") data1 = yield f1.d data2 = yield f2.d self.assertEqual(data1, b"hello\n") self.assertEqual(data2, b"hello\n") yield w1.close() yield w2.close()
def test_control(self): eq = EventualQueue(reactor) w1 = wormhole.create(APPID, self.relayurl, reactor, _enable_dilate=True) w2 = wormhole.create(APPID, self.relayurl, reactor, _enable_dilate=True) w1.allocate_code() code = yield w1.get_code() print("code is: {}".format(code)) w2.set_code(code) yield doBoth(w1.get_verifier(), w2.get_verifier()) print("connected") eps1 = w1.dilate() eps2 = w2.dilate() print("w.dilate ready") f1 = Factory() f1.protocol = L f1.d = Deferred() f1.d.addCallback(lambda data: eq.fire_eventually(data)) d1 = eps1.control.connect(f1) f2 = Factory() f2.protocol = L f2.d = Deferred() f2.d.addCallback(lambda data: eq.fire_eventually(data)) d2 = eps2.control.connect(f2) yield d1 yield d2 print("control endpoints connected") # note: I'm making some horrible assumptions about one-to-one writes # and reads across a TCP stack that isn't obligated to maintain such # a relationship, but it's much easier than doing this properly. If # the tests ever start failing, do the extra work, probably by # using a twisted.protocols.basic.LineOnlyReceiver data1 = yield f1.d data2 = yield f2.d self.assertEqual(data1, b"hello\n") self.assertEqual(data2, b"hello\n") yield w1.close() yield w2.close()
def testStopTrying(self): f = Factory() f.protocol = In f.connections = 0 f.allMessages = [] f.goal = 2 f.d = defer.Deferred() c = ReconnectingClientFactory() c.initialDelay = c.delay = 0.2 c.protocol = Out c.howManyTimes = 2 self.port = reactor.listenTCP(0, f) port = self.port PORT = port.getHost().port reactor.connectTCP('127.0.0.1', PORT, c) f.d.addCallback(self._testStopTrying_1, f, c) return f.d
def testStopTrying(self): f = Factory() f.protocol = In f.connections = 0 f.allMessages = [] f.goal = 2 f.d = defer.Deferred() c = ReconnectingClientFactory() c.initialDelay = c.delay = 0.2 c.protocol = Out c.howManyTimes = 2 port = self.port = reactor.listenTCP(0, f) PORT = port.getHost().port reactor.connectTCP('127.0.0.1', PORT, c) f.d.addCallback(self._testStopTrying_1, f, c) return f.d