Copilot commented on code in PR #342:
URL: https://github.com/apache/hugegraph-ai/pull/342#discussion_r3337406269
##########
hugegraph-python-client/src/tests/api/test_metric.py:
##########
@@ -70,10 +105,47 @@ def test_metrics_operations(self):
self.assertIsInstance(statistics, dict)
backend_metrics = self.metrics.get_backend_metrics()
- # In HugeGraph 1.7.0+, the backend_metrics structure changed
- # It's still a dict, but the "hugegraph" key may not exist in the same
format
- self.assertIsInstance(backend_metrics, dict)
- self.assertTrue(backend_metrics, "backend metrics should not be empty")
- # Only assert on the "hugegraph" key if it exists (for backward
compatibility)
- if "hugegraph" in backend_metrics:
- self.assertGreater(len(backend_metrics["hugegraph"]), 1)
+
+ # HugeGraph 1.7.0 backend_metrics shape (top-level key may be
"<cluster>-<graph>"):
+ # { "<cluster>-<graph>": { "backend": str, "nodes": int, "cluster_id":
str,
+ # "servers": { "<server_name>": { <metrics> }
} } }
+ self.assertIsInstance(backend_metrics, dict, "backend_metrics should
be a dict")
+ self.assertTrue(backend_metrics, "backend_metrics should not be empty")
+
+ # Select the graph entry deterministically by matching the configured
graph name
+ graph_key = next(
+ (k for k in backend_metrics if "hugegraph" in k),
+ None,
+ )
+ self.assertIsNotNone(
+ graph_key,
+ f"Expected a key containing 'hugegraph' in backend_metrics, got:
{list(backend_metrics.keys())}",
+ )
Review Comment:
The graph key selection is hard-coded to the substring "hugegraph" and
depends on dict iteration order. This can become non-deterministic (and
contradicts the comment about using the configured graph name) if the backend
returns multiple graph entries, or if the test graph name is ever changed via
ClientUtils.GRAPH. Use the configured graph name and select the matching entry
deterministically (e.g., exact match or "<cluster>-<graph>" suffix), and assert
there is exactly one match.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]