def test_zmqserver_exc(self): import gevent from synapse.node import ZMQServer, ZMQClient, NodeException conf_srv = {'uri': 'tcp://*:5557', 'name': 'zmqsrv'} conf_cli = {'uri': 'tcp://localhost:5557', 'name': 'zmqcli'} def srv_handler(msg): raise NodeException("buggy", "exc_result") server = ZMQServer(conf_srv, srv_handler) self.assertTrue(server.socket is None) server.start() self.assertTrue(server.socket is not None) self.assertRaises(NotImplementedError, server.send, "unimplemented") serverlet = gevent.spawn(server.loop) client = ZMQClient(conf_cli) self.assertTrue(client.socket is None) client.connect() self.assertTrue(client.socket is not None) client.send("sync_message") response = client.recv() self.assertEquals(response, "exc_result") gevent.kill(serverlet) client.close() server.stop()
def test_zmqserver_async(self): import gevent from synapse.node import ZMQServer, ZMQClient, async conf_srv = {'uri': 'tcp://*:5556', 'name': 'zmq_srv_async'} conf_cli = {'uri': 'tcp://localhost:5556', 'name': 'zmq_cli_async'} @async def srv_handler(msg): return "async_response" server = ZMQServer(conf_srv, srv_handler) self.assertTrue(server.socket is None) server.start() self.assertTrue(server.socket is not None) self.assertRaises(NotImplementedError, server.send, "unimplemented") serverlet = gevent.spawn(server.loop) client = ZMQClient(conf_cli) self.assertTrue(client.socket is None) client.connect() self.assertTrue(client.socket is not None) client.send("message") response = client.recv() self.assertEquals(response, "async_response") gevent.sleep(1) gevent.kill(serverlet) client.close() server.stop()