asyncio.sleep(0.01) to asyncio.sleep(0) in tests
authorBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 10:05:14 +0000 (11:05 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Fri, 5 Mar 2021 10:05:14 +0000 (11:05 +0100)
A sleep time of 0 is enough to give control back to the event loop.

controlpi/__init__.py
controlpi/messagebus.py

index b472781b16c8640194d748cb2afe47a870a283d5..a2e3a53bf203a69deb0e5210fa9304788c8f2bfb 100644 (file)
@@ -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.
index 52ec6247e4a56d2c28af009f48ab7fd12cc3a474..ee5a2420a6992280c99fcd355c629d8d324003a1 100644 (file)
@@ -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!