Skip to content

Commit

Permalink
Use task groups in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjpfan committed Dec 4, 2024
1 parent 14f2600 commit 3bbc735
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions kr8s/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,23 @@ 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 = [
pod async for pod in async_api.get("Pod", pod1.name, pod2.name, namespace=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)

0 comments on commit 3bbc735

Please sign in to comment.