mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-03 08:15:53 +00:00
Merge PR #2676: fix(test): fix flaky test_fixed_session_requests_are_serialized
fix(test): fix flaky test_fixed_session_requests_are_serialized
This commit is contained in:
commit
63d646f731
@ -235,15 +235,10 @@ async def test_followup_requests_share_same_session_key(aiohttp_client) -> None:
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_fixed_session_requests_are_serialized(aiohttp_client) -> None:
|
async def test_fixed_session_requests_are_serialized(aiohttp_client) -> None:
|
||||||
order: list[str] = []
|
order: list[str] = []
|
||||||
barrier = asyncio.Event()
|
|
||||||
|
|
||||||
async def slow_process(content, session_key="", channel="", chat_id=""):
|
async def slow_process(content, session_key="", channel="", chat_id=""):
|
||||||
order.append(f"start:{content}")
|
order.append(f"start:{content}")
|
||||||
if content == "first":
|
await asyncio.sleep(0.1)
|
||||||
barrier.set()
|
|
||||||
await asyncio.sleep(0.1)
|
|
||||||
else:
|
|
||||||
await barrier.wait()
|
|
||||||
order.append(f"end:{content}")
|
order.append(f"end:{content}")
|
||||||
return content
|
return content
|
||||||
|
|
||||||
@ -264,7 +259,11 @@ async def test_fixed_session_requests_are_serialized(aiohttp_client) -> None:
|
|||||||
r1, r2 = await asyncio.gather(send("first"), send("second"))
|
r1, r2 = await asyncio.gather(send("first"), send("second"))
|
||||||
assert r1.status == 200
|
assert r1.status == 200
|
||||||
assert r2.status == 200
|
assert r2.status == 200
|
||||||
assert order.index("end:first") < order.index("start:second")
|
# Verify serialization: one process must fully finish before the other starts
|
||||||
|
if order[0] == "start:first":
|
||||||
|
assert order.index("end:first") < order.index("start:second")
|
||||||
|
else:
|
||||||
|
assert order.index("end:second") < order.index("start:first")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not installed")
|
@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not installed")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user