Skip to content

[core] refactor: consolidate _common test files under _common/tests directory#53543

Merged
edoakes merged 2 commits intoray-project:masterfrom
codope:unify-test-utils
Jun 5, 2025
Merged

[core] refactor: consolidate _common test files under _common/tests directory#53543
edoakes merged 2 commits intoray-project:masterfrom
codope:unify-test-utils

Conversation

@codope
Copy link
Copy Markdown
Contributor

@codope codope commented Jun 4, 2025

Why are these changes needed?

In #53457 we moved signal and semaphore to _common/ which is used in serve tests. However, after that, _common had two test_utils which was confusing. This PR reorganizes the test utilities and their tests for better clarity:

Key Changes:

  • Keep SignalActor and Semaphore test utility classes in _common/test_utils.py to ensure they're included in Ray package distribution (external libraries need access to these)
  • Separate tests for utility functions into _common/tests/test_utils.py (tests for ray._common.utils functions)
  • Rename and move tests for test utility classes to _common/tests/test_signal_semaphore_utils.py (tests for SignalActor and Semaphore)
  • Add comprehensive documentation and comments explaining the organization

Final Organization:

  • _common/test_utils.py: Test utility classes (SignalActor, Semaphore) - distributed with Ray package
  • _common/tests/test_utils.py: Tests for Ray utility functions (get_or_create_event_loop, run_background_task)
  • _common/tests/test_signal_semaphore_utils.py: Tests for test utility classes

This resolves the confusion of having multiple test_utils files while ensuring test utilities remain accessible to external libraries that depend on Ray. The separation maintains clear boundaries between utility classes (for distribution) and their tests (for development).

Copilot AI review requested due to automatic review settings June 4, 2025 06:55
@codope codope requested review from aslonnie and edoakes as code owners June 4, 2025 06:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors and consolidates test utilities by moving SignalActor and Semaphore classes under the _common/tests directory while maintaining a backward compatibility shim. Key changes include moving and renaming test utility files, updating import paths in tests, and updating the build file accordingly.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
python/ray/_common/tests/test_utils.py Contains the moved SignalActor and Semaphore definitions; missing an asyncio import
python/ray/_common/tests/test_signal_semaphore_utils.py Updated import path for test utilities
python/ray/_common/tests/BUILD Updated test file mapping to reflect the renamed and consolidated files
python/ray/_common/test_utils.py Now acts as a backward compatibility shim importing from the new location
Comments suppressed due to low confidence (1)

python/ray/_common/tests/test_utils.py:22

  • It appears that 'asyncio' is used in the SignalActor class but is not imported. Please add 'import asyncio' at the beginning of the file to ensure proper functionality.
self.ready_event = asyncio.Event()

@codope codope force-pushed the unify-test-utils branch from 9ec7b02 to be91b37 Compare June 4, 2025 07:18
@codope codope added the go add ONLY when ready to merge, run all tests label Jun 4, 2025
@codope codope requested a review from a team June 4, 2025 15:45
Copy link
Copy Markdown
Collaborator

@aslonnie aslonnie left a comment

Choose a reason for hiding this comment

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

(leaving this to @edoakes and core team to review)

@edoakes
Copy link
Copy Markdown
Collaborator

edoakes commented Jun 4, 2025

Move SignalActor and Semaphore test utilities from _common/test_utils.py to _common/tests/test_utils.py

@codope I think this part might be problematic because the tests/ directory isn't part of the Ray package distribution, meaning it won't be accessible to all other tests (library tests etc.). So this part should stay in _common/test_utils.py (similar to _private/test_utils.py).

@edoakes
Copy link
Copy Markdown
Collaborator

edoakes commented Jun 4, 2025

The rest LGTM and thank you for splitting this change out into its own PR 👍

Signed-off-by: Sagar Sumit <sagarsumit09@gmail.com>
@codope codope force-pushed the unify-test-utils branch from be91b37 to 3e30f11 Compare June 5, 2025 03:07
@codope
Copy link
Copy Markdown
Contributor Author

codope commented Jun 5, 2025

Move SignalActor and Semaphore test utilities from _common/test_utils.py to _common/tests/test_utils.py

@codope I think this part might be problematic because the tests/ directory isn't part of the Ray package distribution, meaning it won't be accessible to all other tests (library tests etc.). So this part should stay in _common/test_utils.py (similar to _private/test_utils.py).

Got it, I have moved back SignalActor and Semaphore to _common/test_utils.py to ensure they're included in Ray package distribution. Also, updated docstrings to make it more clear for future.

…n accessible in the distributed Ray package

Signed-off-by: Sagar Sumit <sagarsumit09@gmail.com>
@codope codope force-pushed the unify-test-utils branch from 3e30f11 to c07f822 Compare June 5, 2025 03:22
@edoakes edoakes merged commit b3e2208 into ray-project:master Jun 5, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants