[Data] add explicit args for mocking _AutoscalingCoordinatorActor#60037
[Data] add explicit args for mocking _AutoscalingCoordinatorActor#60037bveeramani merged 4 commits intoray-project:masterfrom
_AutoscalingCoordinatorActor#60037Conversation
Signed-off-by: machichima <nary12321@gmail.com>
There was a problem hiding this comment.
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.
Signed-off-by: machichima <nary12321@gmail.com>
|
@bveeramani PTAL. Thank you! |
| global MOCKED_TIME | ||
| MOCKED_TIME = 0 | ||
|
|
||
| mock_request_resources = Mock() | ||
| as_coordinator = _AutoscalingCoordinatorActor( | ||
| get_current_time=mock_time, |
There was a problem hiding this comment.
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?
| 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, |
There was a problem hiding this comment.
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
Signed-off-by: machichima <nary12321@gmail.com>
…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>
…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>
…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>
…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>
…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>
Description
As mentioned in #59740 (comment), add explicit args in
_AutoscalingCoordinatorActorconstructor to improve maintainability.Related issues
Follow-up: #59740
Additional information
patch