From 3817d2c67b0b0bca80abcabb14aca438f6eda5c4 Mon Sep 17 00:00:00 2001 From: timmy Date: Wed, 12 Aug 2026 23:52:56 +0000 Subject: [PATCH] test: stabilize recap concurrency verification (Closes #689) --- tests/test_today_recap.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/test_today_recap.py b/tests/test_today_recap.py index 435a456..074fa75 100644 --- a/tests/test_today_recap.py +++ b/tests/test_today_recap.py @@ -1,7 +1,6 @@ import asyncio import json import subprocess -import time from pathlib import Path import httpx @@ -275,6 +274,8 @@ async def test_recap_time_logging_attempts_multiple_entries_with_bounded_concurr active = 0 peak = 0 attempted = [] + first_wave_started = asyncio.Event() + release_first_wave = asyncio.Event() async def user(): return {"id": 1, "login": "Timmy"} @@ -284,8 +285,10 @@ async def test_recap_time_logging_attempts_multiple_entries_with_bounded_concurr active += 1 peak = max(peak, active) attempted.append(identity) + if len(attempted) == 3: + first_wave_started.set() try: - await asyncio.sleep(0.1) + await release_first_wave.wait() finally: active -= 1 @@ -305,17 +308,24 @@ async def test_recap_time_logging_attempts_multiple_entries_with_bounded_concurr await client.post("/api/v1/session", json={"access_token": "correct horse battery staple"}) headers = {"Origin": "https://test", "X-CSRF-Token": client.cookies["stackchain_csrf"]} grant = await recap_time_grant(client, headers, payload) - started = time.perf_counter() - response = await client.post( - "/api/v1/today/recaps/log-time", - json=payload, - headers={**headers, "X-Step-Up-Grant": grant}, + request = asyncio.create_task( + client.post( + "/api/v1/today/recaps/log-time", + json=payload, + headers={**headers, "X-Step-Up-Grant": grant}, + ) ) - elapsed = time.perf_counter() - started + await asyncio.wait_for(first_wave_started.wait(), timeout=1) + await asyncio.sleep(0) + assert active == 3 + assert peak == 3 + assert len(attempted) == 3 + assert not request.done() + release_first_wave.set() + response = await request assert response.status_code == 200 - assert elapsed < 0.35 - assert 1 < peak <= 3 + assert peak == 3 assert set(attempted) == set(identities) assert response.json()["time_logs"] == [ {"identity": identity, "status": "logged"} for identity in identities -- 2.43.0