refactor(miles): share router URL acquisition logic#10
Open
TianyeGGBond wants to merge 1 commit into
Open
Conversation
1463fef to
1e06196
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
MilesRouter._use_url()is the sync selector used by direct tests, while_use_url_async()is the production proxy selector. Both paths had the same two-line acquisition logic:That duplication is risky because the tested sync path and production async path can drift. The async path also has an important locking invariant: the in-flight count increment must remain inside
_workers_changed's condition lock.Change
_pick_least_loaded(candidates)to own the shared "select least-loaded URL + increment in-flight count" operation._use_url()and_use_url_async()._use_url_async()calling the helper inside the existing condition lock, preserving the concurrency invariant._use_url_async()so the production selector path has direct coverage for the same least-load behavior already tested on_use_url().Risk
Low. This is a mechanical refactor of identical code. It should not change Ray/runtime behavior because:
_candidate_set()is unchanged._use_url()still raises on empty candidates._use_url_async()still waits for a non-empty candidate set._use_url_async()still increments the request count while holding_workers_changed's lock.The main risk would be accidentally moving the async increment outside the lock; this PR does not do that.
Validation
Passed syntax/whitespace checks:
Passed a focused local selector check with a temporary Ray import stub:
Local pytest limitation:
This Windows environment cannot collect the fast router test module without the full project dependencies installed. Collection is blocked by missing packages (
rayfirst, thensglangafter a temporary Ray stub). The new test is still included for CI/full dev environments where the fast router suite dependencies are present.