Repository navigation
test(session-routing): seed exited-worker sessions deterministically - #5625
deavgprime wants to merge 1 commit into
Conversation
Signed-off-by: deavgprime <[email protected]>
| async with aiohttp.ClientSession( | ||
| connector=aiohttp.UnixConnector(path), cookie_jar=aiohttp.DummyCookieJar() | ||
| ) as client: | ||
| for _ in range(2): |
There was a problem hiding this comment.
Keep the scale of the post-kill burst here.
Before this change, the test sent 200 verifies at once after the kill, and every session the killed worker held was among them.
That was the only place where many requests from one worker are forwarded to the same dead socket at the same time.
On that path, each failed forward calls _discard_client, which closes the shared client that other requests may still be connecting through.
Those requests still get 410 today, but nothing else in the suite sends them concurrently: the router unit tests send one at a time.
With two sessions per worker, only two requests reach the dead socket, so a regression in that race would go unnoticed.
Seeding EPISODES sessions adds roughly 8 seconds to the test, and the test stays deterministic because each worker is still seeded through its own socket:
| for _ in range(2): | |
| for _ in range(EPISODES // WORKERS): |
| assert len(owners) == WORKERS, owners | ||
| # uvicorn replaces the worker; the replacement does not hold the killed worker's sessions. | ||
| victim = deployment.resources_worker_of(owners.most_common(1)[0][0]) | ||
| victim_owner = owners.most_common(1)[0][0] |
There was a problem hiding this comment.
Nit: every worker now holds the same number of sessions, so most_common returns whichever owner was inserted first.
The call reads as if the counts could differ.
Naming the choice directly would say what the test means:
| victim_owner = owners.most_common(1)[0][0] | |
| victim_owner = next(iter(owners)) |
| assert all( | ||
| owner_of[_session_id(cookies)] in lost_owners for cookies, r in zip(sessions, responses) if r.status != 200 | ||
| r.status == (410 if owner_of[_session_id(cookies)] == victim_owner else 200) | ||
| for cookies, r in zip(sessions, responses) | ||
| ) |
There was a problem hiding this comment.
When this assertion fails, pytest reports only assert False, with no hint of which session got which status.
It is also the only assertion that catches a killed worker's session answering 200 or 502 while the other one answers 410.
Collecting the mismatches would make a CI failure readable without a rerun:
| assert all( | |
| owner_of[_session_id(cookies)] in lost_owners for cookies, r in zip(sessions, responses) if r.status != 200 | |
| r.status == (410 if owner_of[_session_id(cookies)] == victim_owner else 200) | |
| for cookies, r in zip(sessions, responses) | |
| ) | |
| mismatches = [ | |
| (owner_of[_session_id(cookies)], r.status) | |
| for cookies, r in zip(sessions, responses) | |
| if r.status != (410 if owner_of[_session_id(cookies)] == victim_owner else 200) | |
| ] | |
| assert not mismatches, mismatches |
What changed and why
The exited-worker test can put all 200 seed requests on one worker through the shared TCP listener. It then fails its setup assertion before testing the worker exit, as reported in #5433.
Seed two sessions on each worker through its private socket and check the recorded owner. After killing one worker and waiting for its replacement, verify all sessions through the public HTTP endpoint. Assert that both sessions from the killed worker return 410 and every surviving session returns 200 with reward 1.
The socket probe is shared with the existing readiness check. Worker shutdown and replacement timeouts are preserved.
Fixes #5433.
Validation
NEMO_GYM_MULTIWORKER_E2E=1 RAY_TMPDIR=/tmp python -m pytest -q tests/e2e/session_routing/test_session_routing_e2e.py tests/unit_tests/server_runtime/test_session_routing.py --cpu: 94 passed.Serialized seed requests with an async lock to force connection reuse. The original test failed with all 200 sessions on one worker; the fixed test passed under the same constraint.
Temporarily changed the lost-worker response from 410 to 404. The revised test failed at the lost-owner assertion. Restored the runtime code afterward.
python -m pre_commit run --all-files --verbose: passed. The guardwords hook skipped its scan because the private catalog is unavailable.Rollout evidence: N/A, test-only change. The end-to-end tests use real local server processes and a fake inference backend.