Skip to content

[Serve] Make gang scheduling tests avoid handle-based placement checks - #64345

Merged
abrarsheikh merged 4 commits into
ray-project:masterfrom
wanadzhar913:fix/avoid-handle-based-placement-checks
Jul 9, 2026
Merged

abrarsheikh merged 4 commits into
ray-project:masterfrom
wanadzhar913:fix/avoid-handle-based-placement-checks

Conversation

@wanadzhar913

@wanadzhar913 wanadzhar913 commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Several gang scheduling tests inferred replica placement by issuing repeated
DeploymentHandle calls and counting the distinct nodes / gangs / replicas
observed in the responses. Request routing is not a scheduler-state API: with
locality-aware routing (added per-deployment and parameterized in #63629),
repeated calls may legitimately prefer local replicas, so these tests can
undercount nodes, gangs, or replicas even when scheduler state is correct.

This PR makes the tests read placement directly from controller replica state
instead of inferring it from handle responses.

Changes

In test_gang_scheduling.py:

  • Add helpers to read RUNNING replicas (and their node / gang IDs) from
    controller state.
  • Verify placement via controller state in test_incomplete_deployment,
    test_gang_scheduling_spread_strategy, test_gang_context,
    test_scale_gang_boundary, and test_gang_migration.
  • Keep handle calls where the test checks request serving or zero-downtime, and
    add comments documenting the remaining handle-based loops that are safe under
    locality routing (PACK / placement-group invariant checks, single-node
    discovery).

Note: the originally-planned test_deployment_scheduler_downscale.py change was
dropped — #64325 already converted that test to controller-state waiting on
master.

Related issues

Tests

pytest python/ray/serve/tests/test_gang_scheduling.py -q

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors tests in test_deployment_scheduler_downscale.py and test_gang_scheduling.py to verify replica states and counts directly via controller state and serve.status() rather than relying on handle routing, which can be affected by locality routing. Feedback on these changes suggests handling potential KeyError exceptions in the newly added _wait_until_running_replicas helper to prevent premature test failures when applications or deployments are not yet registered in serve.status().

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@wanadzhar913
wanadzhar913 requested a review from a team as a code owner June 25, 2026 17:42
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Jun 25, 2026
@abrarsheikh

Copy link
Copy Markdown
Contributor

why does #63629 change the test behavior should the default still be prefer local routing to False?

abrarsheikh and others added 3 commits July 6, 2026 00:07
Signed-off-by: abrar <[email protected]>

# Conflicts:
#	python/ray/serve/tests/test_deployment_scheduler_downscale.py
test_gang_context inferred gang membership by looping up to 100
handle.remote() calls until it observed all 4 replicas. Under
locality-aware routing (parameterized in ray-project#63629) this loop only hits
local replicas and never sees all gangs, so it would undercount like the
other handle-based placement checks this PR converts.

Read the GangContext from controller replica state instead. The
controller stores the exact GangContext each replica reports from its
own ReplicaContext (round-tripped via initialize_and_get_metadata), so
this verifies the same values deterministically without depending on
request routing.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: abrar <[email protected]>
Several loops still infer placement/gang structure through handle
routing. Add comments explaining why each is safe under locality-aware
routing so they are not mistaken for the pattern this PR converts:

- PACK strategy node check: asserts all replicas share one node; routing
  can only surface a subset of nodes, so it cannot inflate the count.
- Placement-group info checks: each response is a self-contained
  per-replica invariant, so sampling any subset is sufficient.
- Startup-failure and health-failure gang discovery: single-node
  clusters (ray.init(num_cpus=1)), so every replica is local and
  locality routing still reaches all of them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: abrar <[email protected]>
@abrarsheikh
abrarsheikh force-pushed the fix/avoid-handle-based-placement-checks branch from ef683d6 to e699782 Compare July 6, 2026 00:07
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Jul 6, 2026
@wanadzhar913

Copy link
Copy Markdown
Contributor Author

Hi there, abrarsheikh. Many apologies for not being able to work on this the past week, and for missing your question. Tysm for helping me unblock myself!

@jeffreywang88 jeffreywang88 self-assigned this Jul 6, 2026

@jeffreywang88 jeffreywang88 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for making the tests more robust!

@abrarsheikh
abrarsheikh merged commit af4979d into ray-project:master Jul 9, 2026
4 checks passed
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
ray-project#64345)

## Summary

Several gang scheduling tests inferred replica placement by issuing
repeated
`DeploymentHandle` calls and counting the distinct nodes / gangs /
replicas
observed in the responses. Request routing is not a scheduler-state API:
with
locality-aware routing (added per-deployment and parameterized in
ray-project#63629),
repeated calls may legitimately prefer local replicas, so these tests
can
undercount nodes, gangs, or replicas even when scheduler state is
correct.

This PR makes the tests read placement directly from controller replica
state
instead of inferring it from handle responses.

## Changes

In `test_gang_scheduling.py`:
- Add helpers to read RUNNING replicas (and their node / gang IDs) from
  controller state.
- Verify placement via controller state in `test_incomplete_deployment`,
  `test_gang_scheduling_spread_strategy`, `test_gang_context`,
  `test_scale_gang_boundary`, and `test_gang_migration`.
- Keep handle calls where the test checks request serving or
zero-downtime, and
add comments documenting the remaining handle-based loops that are safe
under
  locality routing (PACK / placement-group invariant checks, single-node
  discovery).

Note: the originally-planned `test_deployment_scheduler_downscale.py`
change was
dropped — ray-project#64325 already converted that test to controller-state waiting
on
master.

## Related issues
- Related to ray-project#59929
- Depends on / unblocks ray-project#63629

## Tests

```bash
pytest python/ray/serve/tests/test_gang_scheduling.py -q
```

---------

Signed-off-by: wanadzhar913 <[email protected]>
Signed-off-by: abrar <[email protected]>
Co-authored-by: abrar <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants