Stabilize recap bounded-concurrency verification #690
|
|
@ -1,7 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -275,6 +274,8 @@ async def test_recap_time_logging_attempts_multiple_entries_with_bounded_concurr
|
||||||
active = 0
|
active = 0
|
||||||
peak = 0
|
peak = 0
|
||||||
attempted = []
|
attempted = []
|
||||||
|
first_wave_started = asyncio.Event()
|
||||||
|
release_first_wave = asyncio.Event()
|
||||||
|
|
||||||
async def user():
|
async def user():
|
||||||
return {"id": 1, "login": "Timmy"}
|
return {"id": 1, "login": "Timmy"}
|
||||||
|
|
@ -284,8 +285,10 @@ async def test_recap_time_logging_attempts_multiple_entries_with_bounded_concurr
|
||||||
active += 1
|
active += 1
|
||||||
peak = max(peak, active)
|
peak = max(peak, active)
|
||||||
attempted.append(identity)
|
attempted.append(identity)
|
||||||
|
if len(attempted) == 3:
|
||||||
|
first_wave_started.set()
|
||||||
try:
|
try:
|
||||||
await asyncio.sleep(0.1)
|
await release_first_wave.wait()
|
||||||
finally:
|
finally:
|
||||||
active -= 1
|
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"})
|
await client.post("/api/v1/session", json={"access_token": "correct horse battery staple"})
|
||||||
headers = {"Origin": "https://test", "X-CSRF-Token": client.cookies["stackchain_csrf"]}
|
headers = {"Origin": "https://test", "X-CSRF-Token": client.cookies["stackchain_csrf"]}
|
||||||
grant = await recap_time_grant(client, headers, payload)
|
grant = await recap_time_grant(client, headers, payload)
|
||||||
started = time.perf_counter()
|
request = asyncio.create_task(
|
||||||
response = await client.post(
|
client.post(
|
||||||
"/api/v1/today/recaps/log-time",
|
"/api/v1/today/recaps/log-time",
|
||||||
json=payload,
|
json=payload,
|
||||||
headers={**headers, "X-Step-Up-Grant": grant},
|
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 response.status_code == 200
|
||||||
assert elapsed < 0.35
|
assert peak == 3
|
||||||
assert 1 < peak <= 3
|
|
||||||
assert set(attempted) == set(identities)
|
assert set(attempted) == set(identities)
|
||||||
assert response.json()["time_logs"] == [
|
assert response.json()["time_logs"] == [
|
||||||
{"identity": identity, "status": "logged"} for identity in identities
|
{"identity": identity, "status": "logged"} for identity in identities
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user