async def main(): client = WSRPCClient("ws://127.0.0.1:8000/ws/", loop=loop) client.add_route('test', sleep) await client.connect() print(await client.call("test")) await client.close()
async def test_emitter(client: WSRPCClient, handler, loop): handler.add_route("emitter", emitter) async with client: future = loop.create_future() client.add_event_listener(future.set_result) await client.proxy.emitter() result = await future assert result == {"Hello": "world"}
async def test_broadcast(client: WSRPCClient, handler: WebSocketAsync, route: Route, loop): async with client: future = loop.create_future() async def on_broadcast(_, result): nonlocal future future.set_result(result) client.add_route("broadcast", on_broadcast) handler.add_route("reverse", route) await client.proxy.reverse(data=None) await asyncio.wait_for(client.proxy.reverse.broadcast(), timeout=999) assert await asyncio.wait_for(future, timeout=5)
async def test_frames_are_sent_in_correct_order(client: WSRPCClient): async with client: data = 'hello, world' * 1024 coros = [ client.call("ping", data=data) for _ in range(100) ] await asyncio.gather(*coros)
async def send_context_change(self, host): """ Calls running webserver to inform about context change Used when new PS/AE should be triggered, but one already running, without this publish would point to old context. """ client = WSRPCClient(os.getenv("WEBSOCKET_URL"), loop=asyncio.get_event_loop()) await client.connect() project = api.Session["AVALON_PROJECT"] asset = api.Session["AVALON_ASSET"] task = api.Session["AVALON_TASK"] log.info("Sending context change to {}-{}-{}".format(project, asset, task)) await client.call('{}.set_context'.format(host), project=project, asset=asset, task=task) await client.close()
async def main(): client = WSRPCClient("ws://127.0.0.1:8000/ws/", loop=loop) await client.connect() print(await client.proxy.uuid4()) await client.close()
async def client(session: ClientSession, socket_path, loop) -> WSRPCClient: return WSRPCClient(socket_path, session=session, loop=loop)