-
Notifications
You must be signed in to change notification settings - Fork 50
fix: page ready agents during health-check startup #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scale-sf
wants to merge
2
commits into
main
Choose a base branch
from
fix/page-ready-healthchecks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−24
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
agentex/tests/unit/temporal/test_run_healthcheck_workflow.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
| from src.temporal import run_healthcheck_workflow | ||
|
|
||
|
|
||
| async def _run_main_with_pages(monkeypatch, pages): | ||
| class FakeGlobalDependencies: | ||
| temporal_client = object() | ||
|
|
||
| async def load(self): | ||
| return None | ||
|
|
||
| class FakeAgentRepository: | ||
| def __init__(self, *args): | ||
| self.calls = [] | ||
|
|
||
| async def list( | ||
| self, | ||
| filters, | ||
| limit, | ||
| page_number, | ||
| order_by, | ||
| order_direction, | ||
| ): | ||
| self.calls.append( | ||
| { | ||
| "filters": filters, | ||
| "limit": limit, | ||
| "page_number": page_number, | ||
| "order_by": order_by, | ||
| "order_direction": order_direction, | ||
| } | ||
| ) | ||
| return pages.get(page_number, []) | ||
|
|
||
| class FakeTemporalAdapter: | ||
| def __init__(self, temporal_client): | ||
| self.temporal_client = temporal_client | ||
| self.started_workflows = [] | ||
|
|
||
| async def start_workflow(self, **kwargs): | ||
| self.started_workflows.append(kwargs) | ||
|
|
||
| fake_repo = FakeAgentRepository() | ||
| fake_adapter = FakeTemporalAdapter(object()) | ||
| fake_env = SimpleNamespace( | ||
| ENABLE_HEALTH_CHECK_WORKFLOW=True, | ||
| AGENTEX_SERVER_TASK_QUEUE="agentex-server", | ||
| ) | ||
|
|
||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "GlobalDependencies", | ||
| FakeGlobalDependencies, | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow.EnvironmentVariables, | ||
| "refresh", | ||
| lambda: fake_env, | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow.TemporalClientFactory, | ||
| "is_temporal_configured", | ||
| lambda env: True, | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "database_async_read_write_engine", | ||
| lambda: object(), | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "database_async_read_write_session_maker", | ||
| lambda engine: object(), | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "database_async_read_only_session_maker", | ||
| lambda engine: object(), | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "AgentRepository", | ||
| lambda *args: fake_repo, | ||
| ) | ||
| monkeypatch.setattr( | ||
| run_healthcheck_workflow, | ||
| "TemporalAdapter", | ||
| lambda temporal_client: fake_adapter, | ||
| ) | ||
|
|
||
| await run_healthcheck_workflow.main() | ||
|
|
||
| return fake_repo, fake_adapter | ||
|
|
||
|
|
||
| def _agents(count: int, prefix: str = "agent"): | ||
| return [ | ||
| SimpleNamespace(id=f"{prefix}-{i}", acp_url=f"http://{prefix}-{i}") | ||
| for i in range(count) | ||
| ] | ||
|
|
||
|
|
||
| def _expected_call(page_number: int): | ||
| return { | ||
| "filters": {"status": run_healthcheck_workflow.AgentStatus.READY}, | ||
| "limit": run_healthcheck_workflow.READY_AGENT_PAGE_SIZE, | ||
| "page_number": page_number, | ||
| "order_by": "id", | ||
| "order_direction": "asc", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.unit | ||
| async def test_main_pages_ready_agents_for_healthcheck(monkeypatch): | ||
| final_agent = SimpleNamespace(id="agent-final", acp_url="http://agent-final") | ||
| fake_repo, fake_adapter = await _run_main_with_pages( | ||
| monkeypatch, | ||
| { | ||
| 1: _agents(run_healthcheck_workflow.READY_AGENT_PAGE_SIZE), | ||
| 2: [final_agent], | ||
| }, | ||
| ) | ||
|
|
||
| assert fake_repo.calls == [_expected_call(1), _expected_call(2)] | ||
| assert len(fake_adapter.started_workflows) == ( | ||
| run_healthcheck_workflow.READY_AGENT_PAGE_SIZE + 1 | ||
| ) | ||
| assert ( | ||
| fake_adapter.started_workflows[-1]["workflow_id"] | ||
| == "healthcheck_workflow_agent-final" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.unit | ||
| async def test_main_checks_empty_page_for_exact_page_size(monkeypatch): | ||
| fake_repo, fake_adapter = await _run_main_with_pages( | ||
| monkeypatch, | ||
| { | ||
| 1: _agents(run_healthcheck_workflow.READY_AGENT_PAGE_SIZE), | ||
| 2: [], | ||
| }, | ||
| ) | ||
|
|
||
| assert fake_repo.calls == [_expected_call(1), _expected_call(2)] | ||
| assert len(fake_adapter.started_workflows) == ( | ||
| run_healthcheck_workflow.READY_AGENT_PAGE_SIZE | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.