Skip to content

Commit 2447a31

Browse files
committed
Pass explicitly created tasks when calling asyncio.await
This is required because as of Python 3.11, passing coroutine objects to wait() directly is forbidden. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 5ddf1f2 commit 2447a31

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

tests/actor/test_power_distributing.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ async def test_power_distributor_one_user(
266266
await client_handle.send(request)
267267

268268
done, pending = await asyncio.wait(
269-
[client_handle.receive()], timeout=SAFETY_TIMEOUT
269+
[asyncio.create_task(client_handle.receive())],
270+
timeout=SAFETY_TIMEOUT,
270271
)
271272
await distributor._stop() # type: ignore # pylint: disable=no-member
272273

@@ -337,7 +338,11 @@ async def test_power_distributor_two_users(
337338
await asyncio.gather(*[task1, task2])
338339

339340
done, pending = await asyncio.wait(
340-
[user1_handle.receive(), user2_handle.receive()], timeout=SAFETY_TIMEOUT
341+
[
342+
asyncio.create_task(user1_handle.receive()),
343+
asyncio.create_task(user2_handle.receive()),
344+
],
345+
timeout=SAFETY_TIMEOUT,
341346
)
342347
await distributor._stop() # type: ignore # pylint: disable=no-member
343348

@@ -394,7 +399,8 @@ async def test_power_distributor_invalid_battery_id(self) -> None:
394399
await user1_handle.send(request)
395400

396401
done, _ = await asyncio.wait(
397-
[user1_handle.receive()], timeout=SAFETY_TIMEOUT
402+
[asyncio.create_task(user1_handle.receive())],
403+
timeout=SAFETY_TIMEOUT,
398404
)
399405
await distributor._stop() # type: ignore # pylint: disable=no-member
400406

@@ -476,9 +482,9 @@ async def test_power_distributor_overlapping_batteries(self) -> None:
476482

477483
done, _ = await asyncio.wait(
478484
[
479-
user1_handle.receive(),
480-
user2_handle.receive(),
481-
user3_handle.receive(),
485+
asyncio.create_task(user1_handle.receive()),
486+
asyncio.create_task(user2_handle.receive()),
487+
asyncio.create_task(user3_handle.receive()),
482488
],
483489
timeout=SAFETY_TIMEOUT,
484490
)
@@ -552,7 +558,8 @@ async def test_power_distributor_one_user_adjust_power_consume(
552558
await user1_handle.send(request)
553559

554560
done, pending = await asyncio.wait(
555-
[user1_handle.receive()], timeout=SAFETY_TIMEOUT
561+
[asyncio.create_task(user1_handle.receive())],
562+
timeout=SAFETY_TIMEOUT,
556563
)
557564
await distributor._stop() # type: ignore # pylint: disable=no-member
558565

@@ -618,7 +625,8 @@ async def test_power_distributor_one_user_adjust_power_supply(
618625
await user1_handle.send(request)
619626

620627
done, pending = await asyncio.wait(
621-
[user1_handle.receive()], timeout=SAFETY_TIMEOUT
628+
[asyncio.create_task(user1_handle.receive())],
629+
timeout=SAFETY_TIMEOUT,
622630
)
623631
await distributor._stop() # type: ignore # pylint: disable=no-member
624632

@@ -684,7 +692,8 @@ async def test_power_distributor_one_user_adjust_power_success(
684692
await user1_handle.send(request)
685693

686694
done, pending = await asyncio.wait(
687-
[user1_handle.receive()], timeout=SAFETY_TIMEOUT
695+
[asyncio.create_task(user1_handle.receive())],
696+
timeout=SAFETY_TIMEOUT,
688697
)
689698
await distributor._stop() # type: ignore # pylint: disable=no-member
690699

@@ -743,7 +752,8 @@ async def test_not_all_batteries_are_working(
743752
await client_handle.send(request)
744753

745754
done, pending = await asyncio.wait(
746-
[client_handle.receive()], timeout=SAFETY_TIMEOUT
755+
[asyncio.create_task(client_handle.receive())],
756+
timeout=SAFETY_TIMEOUT,
747757
)
748758
await distributor._stop() # type: ignore # pylint: disable=no-member
749759

tests/microgrid/test_microgrid_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ async def test_microgrid_api(
115115
_microgrid.get()
116116

117117
tasks = [
118-
_microgrid.initialize("127.0.0.1", 10001),
119-
_microgrid.initialize("127.0.0.1", 10001),
118+
asyncio.create_task(_microgrid.initialize("127.0.0.1", 10001)),
119+
asyncio.create_task(_microgrid.initialize("127.0.0.1", 10001)),
120120
]
121121
initialize_task = asyncio.wait(tasks, return_when=ALL_COMPLETED)
122122

0 commit comments

Comments
 (0)