From: Benjamin Braatz Date: Fri, 5 Mar 2021 10:05:14 +0000 (+0100) Subject: asyncio.sleep(0.01) to asyncio.sleep(0) in tests X-Git-Tag: v0.3.0~74 X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=7df4f81388e937fd1ad3eefe23e11eb53613f37f;p=graphit%2Fcontrolpi.git asyncio.sleep(0.01) to asyncio.sleep(0) in tests A sleep time of 0 is enough to give control back to the event loop. --- diff --git a/controlpi/__init__.py b/controlpi/__init__.py index b472781..a2e3a53 100644 --- a/controlpi/__init__.py +++ b/controlpi/__init__.py @@ -47,7 +47,8 @@ when using the system in production: ... bus_task = asyncio.create_task(bus.run()) ... asyncio.create_task(p.run()) ... await bus.send({'sender': 'Test', 'target': 'Bus Test', 'key': 'v'}) -... await asyncio.sleep(0.01) +... await asyncio.sleep(0) +... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(test_bus_plugin()) BusPlugin 'Bus Test' configured. @@ -67,7 +68,7 @@ client and its registered send and receive templates: ... bus_task = asyncio.create_task(bus.run()) ... await bus.send({'sender': 'Test', 'target': '', ... 'command': 'get clients'}) -... await asyncio.sleep(0.01) +... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(test_bus()) BusPlugin 'Bus Test' configured. diff --git a/controlpi/messagebus.py b/controlpi/messagebus.py index 52ec624..ee5a242 100644 --- a/controlpi/messagebus.py +++ b/controlpi/messagebus.py @@ -59,7 +59,7 @@ have to explicitly cancel the task: ... await setup(bus) ... bus_task = asyncio.create_task(bus.run()) ... await send(bus) -... await asyncio.sleep(0.01) +... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(main()) Sending messages. @@ -501,7 +501,7 @@ class MessageBus: ... await setup(bus) ... bus_task = asyncio.create_task(bus.run()) ... await send(bus) - ... await asyncio.sleep(0.01) + ... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(main()) Setting up. @@ -609,7 +609,7 @@ class MessageBus: >>> async def main(): ... bus = MessageBus() ... bus_task = asyncio.create_task(bus.run()) - ... await asyncio.sleep(0.01) + ... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(main()) """ @@ -645,7 +645,7 @@ class MessageBus: ... await bus.send({'sender': 'Client 2', 'target': 'Client 1'}) ... await bus.send({'sender': 'Client 1', 'target': 'Client 2', ... 'k1': 42}) - ... await asyncio.sleep(0.01) + ... await asyncio.sleep(0) ... bus_task.cancel() >>> asyncio.run(main()) Message not allowed for sender Client 1!