fix: unify detect effective job metrics
This commit is contained in:
122
domain-api/tests/test_detect_job_service.py
Normal file
122
domain-api/tests/test_detect_job_service.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import unittest
|
||||
|
||||
from app.services.detect_job_service import _build_effective_node_stats, _build_effective_summary
|
||||
|
||||
|
||||
class DetectJobServiceTests(unittest.TestCase):
|
||||
def test_build_effective_node_stats_keeps_runtime_nodes_and_backfills_unassigned(self) -> None:
|
||||
distributed_node_stats = [
|
||||
{
|
||||
"node_code": "mainland-controller-01",
|
||||
"items_total": 200,
|
||||
"items_pending": 195,
|
||||
"items_claimed": 0,
|
||||
"items_running": 5,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "mainland-worker-01",
|
||||
"items_total": 70,
|
||||
"items_pending": 56,
|
||||
"items_claimed": 9,
|
||||
"items_running": 5,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "overseas-control-01",
|
||||
"items_total": 50,
|
||||
"items_pending": 0,
|
||||
"items_claimed": 25,
|
||||
"items_running": 4,
|
||||
"items_completed": 21,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "unassigned",
|
||||
"items_total": 950,
|
||||
"items_pending": 950,
|
||||
"items_claimed": 0,
|
||||
"items_running": 0,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
]
|
||||
|
||||
node_stats = _build_effective_node_stats(
|
||||
distributed_node_stats=distributed_node_stats,
|
||||
raw_items_total=1000,
|
||||
)
|
||||
|
||||
self.assertEqual(4, len(node_stats))
|
||||
unassigned = next(item for item in node_stats if item["node_code"] == "unassigned")
|
||||
self.assertEqual(680, unassigned["items_total"])
|
||||
self.assertEqual(680, unassigned["items_pending"])
|
||||
self.assertEqual("central_queue", unassigned["metrics_source"])
|
||||
|
||||
def test_build_effective_summary_uses_effective_node_stats_and_raw_blacklisted(self) -> None:
|
||||
node_stats = [
|
||||
{
|
||||
"node_code": "mainland-controller-01",
|
||||
"items_total": 200,
|
||||
"items_pending": 195,
|
||||
"items_claimed": 0,
|
||||
"items_running": 5,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "mainland-worker-01",
|
||||
"items_total": 70,
|
||||
"items_pending": 56,
|
||||
"items_claimed": 9,
|
||||
"items_running": 5,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "overseas-control-01",
|
||||
"items_total": 50,
|
||||
"items_pending": 0,
|
||||
"items_claimed": 25,
|
||||
"items_running": 4,
|
||||
"items_completed": 21,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
{
|
||||
"node_code": "unassigned",
|
||||
"items_total": 680,
|
||||
"items_pending": 680,
|
||||
"items_claimed": 0,
|
||||
"items_running": 0,
|
||||
"items_completed": 0,
|
||||
"items_blacklisted": 0,
|
||||
"items_failed": 0,
|
||||
},
|
||||
]
|
||||
|
||||
summary = _build_effective_summary(
|
||||
node_stats=node_stats,
|
||||
raw_items_total=1000,
|
||||
raw_items_blacklisted=3,
|
||||
)
|
||||
|
||||
self.assertEqual(1000, summary["items_total"])
|
||||
self.assertEqual(931, summary["items_pending"])
|
||||
self.assertEqual(34, summary["items_claimed"])
|
||||
self.assertEqual(14, summary["items_running"])
|
||||
self.assertEqual(21, summary["items_completed"])
|
||||
self.assertEqual(3, summary["items_blacklisted"])
|
||||
self.assertEqual(24, summary["items_terminal"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user