feat: stabilize multi-region runtime sync and worker orchestration
This commit is contained in:
93
domain-api/tests/test_runtime_api_routes.py
Normal file
93
domain-api/tests/test_runtime_api_routes.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.api.routes import runtime as runtime_route
|
||||
|
||||
|
||||
class RuntimeApiRoutesTests(unittest.TestCase):
|
||||
@patch("app.api.routes.runtime.list_debug_events")
|
||||
def test_runtime_debug_events_forwards_node_code_filter(self, mock_list_debug_events) -> None:
|
||||
mock_list_debug_events.return_value = {"records": [], "has_more": False}
|
||||
|
||||
response = runtime_route.runtime_debug_events(node_code="mainland-controller-01-a", limit=20)
|
||||
|
||||
self.assertEqual(0, response.code)
|
||||
mock_list_debug_events.assert_called_once_with(
|
||||
limit=20,
|
||||
service=None,
|
||||
event_type=None,
|
||||
source_region=None,
|
||||
node_code="mainland-controller-01-a",
|
||||
level=None,
|
||||
before_id=None,
|
||||
after_id=None,
|
||||
created_after=None,
|
||||
)
|
||||
|
||||
@patch("app.api.routes.runtime.get_runtime_status")
|
||||
@patch("app.api.routes.runtime.get_sync_summary")
|
||||
@patch("app.api.routes.runtime.get_debug_handoff_report")
|
||||
def test_runtime_health_handover_filters_recent_issues_and_issue_groups_by_node_code(
|
||||
self,
|
||||
mock_get_debug_handoff_report,
|
||||
mock_get_sync_summary,
|
||||
mock_get_runtime_status,
|
||||
) -> None:
|
||||
mock_get_sync_summary.return_value = {"latest_record": {}}
|
||||
mock_get_runtime_status.return_value = {"readiness": {"status": "ready"}}
|
||||
mock_get_debug_handoff_report.return_value = {
|
||||
"overview": {
|
||||
"recent_issues": [
|
||||
{"node_code": "mainland-controller-01", "message": "keep"},
|
||||
{"node_code": "mainland-worker-01", "message": "drop"},
|
||||
]
|
||||
},
|
||||
"recent_issues": [
|
||||
{"node_code": "mainland-controller-01", "message": "keep"},
|
||||
{"node_code": "mainland-worker-01", "message": "drop"},
|
||||
],
|
||||
"issue_groups": [
|
||||
{"node_code": "mainland-controller-01", "message": "keep"},
|
||||
{"node_code": "mainland-worker-01", "message": "drop"},
|
||||
],
|
||||
"failure_handoff": {
|
||||
"recent_issues": [
|
||||
{"node_code": "mainland-controller-01", "message": "keep"},
|
||||
{"node_code": "mainland-worker-01", "message": "drop"},
|
||||
],
|
||||
"issue_groups": [
|
||||
{"node_code": "mainland-controller-01", "message": "keep"},
|
||||
{"node_code": "mainland-worker-01", "message": "drop"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
response = runtime_route.runtime_health_handover(node_code="mainland-controller-01")
|
||||
|
||||
self.assertEqual(0, response.code)
|
||||
self.assertEqual(
|
||||
[{"node_code": "mainland-controller-01", "message": "keep"}],
|
||||
response.data["recent_issues"],
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"node_code": "mainland-controller-01", "message": "keep"}],
|
||||
response.data["issue_groups"],
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"node_code": "mainland-controller-01", "message": "keep"}],
|
||||
response.data["overview"]["recent_issues"],
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"node_code": "mainland-controller-01", "message": "keep"}],
|
||||
response.data["failure_handoff"]["recent_issues"],
|
||||
)
|
||||
self.assertEqual(
|
||||
[{"node_code": "mainland-controller-01", "message": "keep"}],
|
||||
response.data["failure_handoff"]["issue_groups"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user