def go(loop): handler_coro = create_mock_game() shim = yield from aioredux_shim.create_shim(handler_coro, loop=loop) self.assertIsNotNone(shim) transport, protocol = shim yield from protocol.close()
def go(loop): app = aioredux_frontend.make_app(static_path, loop=loop) srv = yield from loop.create_server(app.make_handler(), host, port) # setup (mock) shim handler_coro = create_mock_game() shim = yield from aioredux_shim.create_shim(handler_coro, loop=loop) return (srv, shim)
def go(loop): if loop is not None: # this is needed as there is no other way to pass a loop to aioamqp asyncio.set_event_loop(loop) rpc_queue_name = 'rpc_queue' result_queue_name = str(uuid.uuid4()) # unique queue for websocket rpc_success = False # make rpc request so shim sees it when it starts transport, protocol = yield from aioamqp.connect('localhost') rpc_channel = yield from protocol.channel() # different channel for rpc yield from rpc_channel.queue_declare(result_queue_name, exclusive=True) @asyncio.coroutine def on_response(body, envelope, properties): nonlocal rpc_success rpc_success = True self.assertEqual(json.loads(body.decode('utf8')), {'type': 'MOCK_ACTION_TYPE'}) rpc_channel = yield from protocol.channel() # different channel for rpc correlation_id = str(uuid.uuid4()) properties = {'reply_to': result_queue_name, 'correlation_id': correlation_id} yield from rpc_channel.basic_publish(json.dumps({'type': 'TEST_ACTION'}), '', routing_key=rpc_queue_name, properties=properties) # setup shim, rpc request should be waiting handler_coro = create_mock_game() transport, protocol = yield from aioredux_shim.create_shim(handler_coro, loop=loop) # rpc response should not be ready yield from rpc_channel.basic_consume(result_queue_name, callback=on_response) # cleanup yield from protocol.close() print("GOT SOMETHING!!!!", rpc_success) self.assertTrue(rpc_success)