def test_main(): logging.basicConfig(level=logging.INFO) loop = asyncio.get_event_loop() client = Client(room="test", loop=loop) basic = Basic(client, loop=loop) basic.bidirectional_link(client) # Execute both client and basic until either of them stops. client.connect() loop.run_until_complete(asyncio.wait([client.task, basic.task])) # Wait on both loop.run_until_complete(asyncio.wait(asyncio.Task.all_tasks(loop=loop))) # Let everything else shutdown cleanly
def test_main(): logging.basicConfig(level=logging.INFO) loop = asyncio.get_event_loop() client = Client(room="test", loop=loop) nick_and_auth = NickAndAuth(client, "nick-and-auth-bot", loop=loop) nick_and_auth.bidirectional_link(client) # Execute both client and nick_and_auth until either of them stops. client.connect() nick_cell = [nick_and_auth.current_nick] async def task(): while nick_and_auth.current_nick != nick_and_auth.desired_nick: await asyncio.sleep(0.0) nick_cell[0] = nick_and_auth.current_nick checker = asyncio.wait_for(task(), timeout=3.0, loop=loop) loop.run_until_complete( asyncio.wait([client.task, nick_and_auth.task, checker], return_when=asyncio.FIRST_COMPLETED) ) # Wait on all three client.exit() # Exit if it didn't crash nick_and_auth.exit() # Exit if it didn't crash loop.run_until_complete(asyncio.wait(asyncio.Task.all_tasks(loop=loop))) # Let everything else shutdown cleanly assert nick_cell[0] == nick_and_auth.desired_nick, "after all of this I hope we got to set our nick"