From 3bbc735fdf90b9ca2762f923cd9d8bfe5a604f1f Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Wed, 4 Dec 2024 07:48:37 -0800 Subject: [PATCH] Use task groups in tests --- kr8s/tests/test_api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kr8s/tests/test_api.py b/kr8s/tests/test_api.py index 8ac16ed..8e19830 100644 --- a/kr8s/tests/test_api.py +++ b/kr8s/tests/test_api.py @@ -425,12 +425,16 @@ async def test_two_pods(example_pod_spec, ns): example_pod_spec_2["metadata"]["name"] = "example-" + uuid.uuid4().hex[:10] pod2 = await Pod(example_pod_spec_2) - pods = [pod1, pod2] - for pod in pods: + async def _create_and_wait(pod): await pod.create() while not await pod.ready(): await anyio.sleep(0.1) + pods = [pod1, pod2] + async with anyio.create_task_group() as tg: + for pod in pods: + tg.start_soon(_create_and_wait, pod) + async_api = await kr8s.asyncio.api() pods_api = [ @@ -438,5 +442,6 @@ async def test_two_pods(example_pod_spec, ns): ] assert len(pods_api) == 2 - for pod in pods: - await pod.delete() + async with anyio.create_task_group() as tg: + for pod in pods: + tg.start_soon(pod.delete)