Skip to content

Commit 9d60739

Browse files
committed
python: wait for the saved session instead of a fixed sleep in sessions.list e2e
The sessions.list e2e test enqueued a turn, slept 200ms, then saved and listed once. On the Windows runners the enqueued turn was not recorded yet when save ran, so sessions.list came back empty and `assert len(listed.sessions) >= 1` failed with `assert 0 >= 1`. Linux and macOS happened to win the race. Replace the fixed sleep with the existing `wait_for_condition` harness helper, re-saving on each attempt until the session actually appears in sessions.list. All discriminator assertions are unchanged, so the boolean-discriminator path this PR fixes is still exercised end-to-end. `asyncio` was imported only for the removed sleep, so drop the import.
1 parent 4c6c817 commit 9d60739

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

python/e2e/test_rpc_server_e2e.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import asyncio
109
import os
1110
import uuid
1211
from datetime import UTC, datetime
@@ -56,7 +55,7 @@
5655
)
5756
from copilot.session import PermissionHandler
5857

59-
from .testharness import E2ETestContext
58+
from .testharness import E2ETestContext, wait_for_condition
6059

6160
pytestmark = pytest.mark.asyncio(loop_scope="module")
6261

@@ -307,16 +306,33 @@ async def test_should_list_find_and_inspect_persisted_session_state(
307306
await session.send(
308307
"Record a turn for sessions.list discriminator coverage", mode="enqueue"
309308
)
310-
await asyncio.sleep(0.2)
311-
save = await client.rpc.sessions.save(SessionsSaveRequest(session_id=session_id))
312-
assert save is not None
313-
314-
listed = await client.rpc.sessions.list(
315-
SessionsListRequest(
316-
filter=SessionListFilter(cwd=str(working_directory)),
317-
metadata_limit=0,
309+
310+
listed = None
311+
312+
async def session_is_listed() -> bool:
313+
nonlocal listed
314+
# Re-save on every attempt: on slower runners the enqueued turn is not
315+
# necessarily recorded yet when the first save runs, so a single save
316+
# followed by a fixed sleep races the CLI's own persistence.
317+
save = await client.rpc.sessions.save(SessionsSaveRequest(session_id=session_id))
318+
assert save is not None
319+
listed = await client.rpc.sessions.list(
320+
SessionsListRequest(
321+
filter=SessionListFilter(cwd=str(working_directory)),
322+
metadata_limit=0,
323+
)
318324
)
325+
return any(item.session_id == session_id for item in listed.sessions or [])
326+
327+
await wait_for_condition(
328+
session_is_listed,
329+
timeout=60.0,
330+
timeout_message=(
331+
"Timed out waiting for the saved session to be returned by sessions.list."
332+
),
319333
)
334+
335+
assert listed is not None
320336
assert listed.sessions is not None
321337
assert len(listed.sessions) >= 1
322338
matching = [item for item in listed.sessions if item.session_id == session_id]

0 commit comments

Comments
 (0)