def testDisconnectDuringTest(self): self.server.transport.loseConnection() yield self.server.connectionLost.called() # since we brutally shut the connection from the server side, advance time # so the client waiting for its close frame times out: yield advanceTime(1) yield advanceTime(1)
def testTick(self): yield self.loginClients() self.factory.start() yield advanceTime(seconds=1.1) compare((yield self.client1.lineReceived.called()), expected=b"<tick> 0") compare((yield self.client2.lineReceived.called()), expected=b"<tick> 0") yield advanceTime(seconds=1.1) compare((yield self.client1.lineReceived.called()), expected=b"<tick> 1") compare((yield self.client2.lineReceived.called()), expected=b"<tick> 1") self.factory.stop()
def testTwoPings(self): expectedId = 'client'+str(id(self.sender)) data = yield self.receiver.datagramReceived.called() compare(data, expected={'id': expectedId}) yield advanceTime(seconds=1.1) data = yield self.receiver.datagramReceived.called() compare(data, expected={'id': expectedId})
def testReconnect(self): hook(ServerTester, 'onOpen') self.client.sendMessage(b'hello', isBinary=True) yield ServerProtocol.sendClose.called() yield self.client.connectionLost.called() client = yield waitForClient(self.context, ServerTester.onOpen, ServerProtocol.connectionMade, 'close') server = client.serverProtocol client = client.clientProtocol client.sendMessage(b'hello') payload = yield client.onMessage.called() compare(payload, expected=b'gotit') # autobahn just doesn't use client protocol instances that aren't open, so # we manually check we're stripped out closed connections: compare(server.factory.state.clients, expected={server}) yield advanceTime(seconds=2.1) payload = yield client.onMessage.called() compare(payload, expected=b'ping 1')
def testWorkTwo(self): LoopingCall(work, self, 0.001).start(2) yield advanceTime(seconds=0.2) yield waitForThreads() cancelDelayedCalls() compare(self.fired, expected=1)
def testLetDeferredsScheduleTheirCalls(self): called = [] reactor.callLater(0, fireLater, called) yield advanceTime(seconds=6) assert called
def testPing(self): yield advanceTime(seconds=2.1) payload = yield self.client.onMessage.called(timeout=0.3) compare(payload, expected=b'ping 1')
def testTwoMessages(self): compare((yield self.server.onMessage.called()), expected=b'tick 1') # advance time until after the loop will have fired: yield advanceTime(seconds=1.1) compare((yield self.server.onMessage.called()), expected=b'tick 2')