Skip to content

[Data] add explicit args for mocking _AutoscalingCoordinatorActor#60037

Merged
bveeramani merged 4 commits intoray-project:masterfrom
machichima:set-param-explicitly
Jan 13, 2026
Merged

[Data] add explicit args for mocking _AutoscalingCoordinatorActor#60037
bveeramani merged 4 commits intoray-project:masterfrom
machichima:set-param-explicitly

Conversation

@machichima
Copy link
Copy Markdown
Contributor

Description

As mentioned in #59740 (comment), add explicit args in _AutoscalingCoordinatorActor constructor to improve maintainability.

Related issues

Follow-up: #59740

Additional information

  • Pass in mock function in testing as args rather than using patch

Signed-off-by: machichima <nary12321@gmail.com>
@machichima machichima requested a review from a team as a code owner January 11, 2026 18:37
Copy link
Copy Markdown
Contributor

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

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 the _AutoscalingCoordinatorActor to accept explicit arguments for its dependencies (get_current_time, send_resources_request, get_cluster_nodes), which is a great improvement for testability and maintainability. This change allows for clean dependency injection in tests, removing the need for unittest.mock.patch. The implementation is well-executed, and the corresponding test files have been updated to leverage this new approach. The changes are correct and improve the overall code quality. I have no further suggestions as the code looks good.

@ray-gardener ray-gardener bot added data Ray Data-related issues community-contribution Contributed by the community labels Jan 11, 2026
Signed-off-by: machichima <nary12321@gmail.com>
@machichima
Copy link
Copy Markdown
Contributor Author

@bveeramani PTAL. Thank you!

Comment on lines +97 to +102
global MOCKED_TIME
MOCKED_TIME = 0

mock_request_resources = Mock()
as_coordinator = _AutoscalingCoordinatorActor(
get_current_time=mock_time,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know this is the existing behavior, but do we need to use a global variable for this? Using a global variable for testing seems unideal

Can we just use a local variable?

Suggested change
global MOCKED_TIME
MOCKED_TIME = 0
mock_request_resources = Mock()
as_coordinator = _AutoscalingCoordinatorActor(
get_current_time=mock_time,
mocked_time = 0
mock_request_resources = Mock()
as_coordinator = _AutoscalingCoordinatorActor(
get_current_time=lambda: mocked_time,

Copy link
Copy Markdown
Contributor Author

@machichima machichima Jan 13, 2026

Choose a reason for hiding this comment

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

Oh yes! I've modified in aa9d428

Also changes other place that use this and removed mock_time() and MOCKED_TIME as they are not used anymore

@bveeramani bveeramani enabled auto-merge (squash) January 12, 2026 19:33
@github-actions github-actions bot disabled auto-merge January 12, 2026 19:33
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Jan 12, 2026
Signed-off-by: machichima <nary12321@gmail.com>
Copy link
Copy Markdown
Member

@bveeramani bveeramani left a comment

Choose a reason for hiding this comment

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

Nice

@bveeramani bveeramani merged commit c92c9b1 into ray-project:master Jan 13, 2026
6 checks passed
rushikeshadhav pushed a commit to rushikeshadhav/ray that referenced this pull request Jan 14, 2026
…ay-project#60037)

## Description

As mentioned in
ray-project#59740 (comment),
add explicit args in `_AutoscalingCoordinatorActor` constructor to
improve maintainability.

## Related issues

Follow-up: ray-project#59740

## Additional information
- Pass in mock function in testing as args rather than using `patch`

---------

Signed-off-by: machichima <nary12321@gmail.com>
Co-authored-by: Balaji Veeramani <balaji@anyscale.com>
jeffery4011 pushed a commit to jeffery4011/ray that referenced this pull request Jan 20, 2026
…ay-project#60037)

## Description

As mentioned in
ray-project#59740 (comment),
add explicit args in `_AutoscalingCoordinatorActor` constructor to
improve maintainability.

## Related issues

Follow-up: ray-project#59740

## Additional information
- Pass in mock function in testing as args rather than using `patch`

---------

Signed-off-by: machichima <nary12321@gmail.com>
Co-authored-by: Balaji Veeramani <balaji@anyscale.com>
Signed-off-by: jeffery4011 <jefferyshen1015@gmail.com>
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Feb 3, 2026
…ay-project#60037)

## Description

As mentioned in
ray-project#59740 (comment),
add explicit args in `_AutoscalingCoordinatorActor` constructor to
improve maintainability.

## Related issues

Follow-up: ray-project#59740

## Additional information
- Pass in mock function in testing as args rather than using `patch`

---------

Signed-off-by: machichima <nary12321@gmail.com>
Co-authored-by: Balaji Veeramani <balaji@anyscale.com>
peterxcli pushed a commit to peterxcli/ray that referenced this pull request Feb 25, 2026
…ay-project#60037)

## Description

As mentioned in
ray-project#59740 (comment),
add explicit args in `_AutoscalingCoordinatorActor` constructor to
improve maintainability.

## Related issues

Follow-up: ray-project#59740

## Additional information
- Pass in mock function in testing as args rather than using `patch`

---------

Signed-off-by: machichima <nary12321@gmail.com>
Co-authored-by: Balaji Veeramani <balaji@anyscale.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
peterxcli pushed a commit to peterxcli/ray that referenced this pull request Feb 25, 2026
…ay-project#60037)

## Description

As mentioned in
ray-project#59740 (comment),
add explicit args in `_AutoscalingCoordinatorActor` constructor to
improve maintainability.

## Related issues

Follow-up: ray-project#59740

## Additional information
- Pass in mock function in testing as args rather than using `patch`

---------

Signed-off-by: machichima <nary12321@gmail.com>
Co-authored-by: Balaji Veeramani <balaji@anyscale.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
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 data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants