Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tests/unit/_autoscaling/test_autoscaled_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ def future(value: T, /) -> Awaitable[T]:
@pytest.mark.run_alone
async def test_runs_concurrently(system_status: SystemStatus | Mock) -> None:
done_count = 0
running_count = 0
max_running_count = 0

async def run() -> None:
nonlocal done_count, running_count, max_running_count
running_count += 1
max_running_count = max(max_running_count, running_count)
await asyncio.sleep(0.1)
nonlocal done_count
running_count -= 1
done_count += 1

pool = AutoscaledPool(
Expand All @@ -54,12 +59,12 @@ async def run() -> None:
),
)

with measure_time() as elapsed:
await pool.run()

assert elapsed.wall is not None
assert elapsed.wall < 0.3
await pool.run()

# Assert the tasks actually ran concurrently by checking the peak number that overlapped in time.
# A sequential (or only partially concurrent) pool would peak below the configured concurrency.
# Previously this was inferred from the total wall time, which was flaky under load on slow CI runners.
assert max_running_count == 10
assert done_count >= 10


Expand Down
Loading