Skip to content

Conversation

@400Ping
Copy link
Contributor

@400Ping 400Ping commented Jan 7, 2026

Description

The DefaultAutoscaler2 implementation needs an AutoscalingCoordinator and a way to get all of the _NodeResourceSpec.

Currently, we can't explicitly inject fake implementations of either dependency. This is problematic because the tests need to assume what the implementation of each dependency looks like and use brittle mocks.

To solve this:

  • Add the FakeAutoscalingCoordinator implementation to a new fake_autoscaling_coordinator.py module (you can use the code below)
  • DefaultClusterAutoscalerV2 has two new parameters autoscaling_coordinator: Optional[AutoscalingCoordinator] = None and get_node_counts: Callable[[], Dict[_NodeResourceSpec, int]] = get_node_resource_spec_and_count. If autoscaling_coordinator is None, you can use the default implementation.
  • Update test_try_scale_up_cluster to use the explicit seams rather than mocks. Where possible, assert against the public interface rather than implementation details

Related issues

Closes #59683

@400Ping 400Ping requested a review from a team as a code owner January 7, 2026 15:06
@400Ping 400Ping marked this pull request as draft January 7, 2026 15:07
Copy link
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 DefaultClusterAutoscalerV2 to support dependency injection for its autoscaling coordinator and node count retrieval logic, making it more testable. It introduces a new FakeAutoscalingCoordinator for testing purposes, which always allocates requested resources. Correspondingly, the tests for DefaultClusterAutoscalerV2 are updated to utilize this new injection mechanism and the fake coordinator, replacing previous mocking. Review comments suggest minor code style improvements, including using the or operator for concise default value assignment in DefaultClusterAutoscalerV2's __init__ method and dict.pop() for more concise item removal in FakeAutoscalingCoordinator.

@400Ping 400Ping marked this pull request as ready for review January 7, 2026 15:43
@ray-gardener ray-gardener bot added core Issues that should be addressed in Ray Core data Ray Data-related issues community-contribution Contributed by the community labels Jan 7, 2026
… for testing

Signed-off-by: 400Ping <fourhundredping@gmail.com>
Signed-off-by: 400Ping <fourhundredping@gmail.com>
@400Ping 400Ping force-pushed the data/AutoscalingCoordinator branch from 91d81c5 to 57efe34 Compare January 9, 2026 14:48
@400Ping
Copy link
Contributor Author

400Ping commented Jan 9, 2026

@bveeramani PTAL

Signed-off-by: 400Ping <fourhundredping@gmail.com>
Signed-off-by: 400Ping <fourhundredping@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 core Issues that should be addressed in Ray Core data Ray Data-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Introduce seams to DefaultAutoscaler2 to make it more testable

2 participants