def test_startServer(self): """ Should call twisted.internet.endpoints.serverFromString and hook that up to the factory """ h = Hub() h.remote_echo = lambda x: x h.startServer(h.getPBServerFactory(), 'tcp:10999') # connect to it self.clientPort = None client = clientFromString(reactor, 'tcp:host=127.0.0.1:port=10999') factory = pb.PBClientFactory() d = client.connect(factory) def saveClient(clientPort): self.clientPort = clientPort d.addCallback(saveClient) d.addCallback(lambda ign: factory.getRootObject()) d.addCallback(lambda obj: obj.callRemote('echo', 'foo')) d.addCallback(lambda res: self.assertEqual(res, 'foo')) d.addCallback(lambda ign: self.clientPort.transport.loseConnection()) d.addCallback(lambda ign: h.stopServer('tcp:10999')) return d
def test_connect(self): """ You can connect to other servers. This is functionalish """ server = Hub() client = Hub() called = [] client.remoteHubFactory = lambda x: 'foo' client.gotRemoteRoot = called.append server.startServer(server.getPBServerFactory(), 'tcp:10999') def check(r): self.assertEqual(called, ['foo'], "Should have called .gotRemoteRoot with wrapped remote") return r d = client.connect('tcp:host=127.0.0.1:port=10999') d.addCallback(check) d.addCallback(lambda x: client.disconnect( 'tcp:host=127.0.0.1:port=10999')) d.addCallback(lambda x: server.stopServer('tcp:10999')) return d