Skip to content

[Serve] Unify test synchronization patterns using shared actor primitives#62191

Merged
abrarsheikh merged 4 commits intoray-project:masterfrom
win5923:unify-serve-test-synchronization
Apr 11, 2026
Merged

[Serve] Unify test synchronization patterns using shared actor primitives#62191
abrarsheikh merged 4 commits intoray-project:masterfrom
win5923:unify-serve-test-synchronization

Conversation

@win5923
Copy link
Copy Markdown
Member

@win5923 win5923 commented Mar 30, 2026

Description

Add reusable sync primitives to serve test_utils and migrate inline/file-based sync patterns to use them.

Related issues

Closes #61387

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

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 centralizes test utility actors—Barrier, Accumulator, and SharedFlag—into ray/serve/_private/test_utils.py and refactors several test suites to use these shared components, replacing local actor definitions and file-based synchronization. The review feedback identifies a missing asyncio import in the utility file that would cause a runtime error and suggests adding comprehensive type hints to the new classes to improve code consistency and clarity.

def __init__(self, n: int):
self._n = n
self._count = 0
self._event = asyncio.Event()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The Barrier class uses asyncio.Event, but asyncio does not appear to be imported in this file. This will cause a NameError at runtime. Please add import asyncio at the top of the file.

self._count = 0
self._event = asyncio.Event()

async def wait(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with other methods, please add a -> None return type hint to this async method.

Suggested change
async def wait(self):
async def wait(self) -> None:

def __init__(self):
self._items = []

def add(self, item):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To improve type safety and for consistency with other type-hinted methods, please add a type hint for the item parameter.

Suggested change
def add(self, item):
def add(self, item: Any):

def add(self, item):
self._items.append(item)

def get(self) -> list:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better type specificity, consider changing the return type hint from list to list[Any]. This is more informative and aligns with modern Python typing practices.

Suggested change
def get(self) -> list:
def get(self) -> list[Any]:

def get(self) -> list:
return list(self._items)

def set_once(self, item) -> bool:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency, please add a type hint for the item parameter.

Suggested change
def set_once(self, item) -> bool:
def set_once(self, item: Any) -> bool:

return True
return False

def get_first(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Please add a return type hint to this method for consistency. Based on the docstring, Optional[Any] would be appropriate. Note that this and other type hint suggestions for this class will require importing Any and Optional from typing.

Suggested change
def get_first(self):
def get_first(self) -> Optional[Any]:

def __init__(self):
self._value = False

def set(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency, please add a -> None return type hint to this method.

Suggested change
def set(self):
def set(self) -> None:

def set(self):
self._value = True

def clear(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency, please add a -> None return type hint to this method.

Suggested change
def clear(self):
def clear(self) -> None:

@win5923 win5923 force-pushed the unify-serve-test-synchronization branch 3 times, most recently from d203441 to b329778 Compare March 30, 2026 15:24
…ives

Signed-off-by: win5923 <ken89@kimo.com>
@win5923 win5923 force-pushed the unify-serve-test-synchronization branch from b329778 to 9ed8b17 Compare March 30, 2026 15:26
@win5923 win5923 marked this pull request as ready for review April 8, 2026 16:30
@win5923 win5923 requested a review from a team as a code owner April 8, 2026 16:30
@ray-gardener ray-gardener bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Apr 8, 2026
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Apr 11, 2026
Copy link
Copy Markdown
Contributor

@abrarsheikh abrarsheikh left a comment

Choose a reason for hiding this comment

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

this is a solid refactor, tysm

@abrarsheikh abrarsheikh enabled auto-merge (squash) April 11, 2026 06:43
@github-actions github-actions bot disabled auto-merge April 11, 2026 09:43
@abrarsheikh abrarsheikh merged commit 996e3da into ray-project:master Apr 11, 2026
6 checks passed
@win5923 win5923 deleted the unify-serve-test-synchronization branch April 11, 2026 15:47
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 go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[serve] Unify serve test synchronization patterns using Ray actors

2 participants