1- """Tests for the Debug class."""
1+ """Tests for the Metrics class."""
22
33from __future__ import annotations
44
5+ from tests .utils .object_assertions import (
6+ assert_match_object ,
7+ assert_object_lists_match ,
8+ )
9+ from typesense .api_call import ApiCall
10+ from typesense .async_api_call import AsyncApiCall
11+ from typesense .async_metrics import AsyncMetrics
512from typesense .metrics import Metrics
613
714
15+ def test_init (fake_api_call : ApiCall ) -> None :
16+ """Test that the Metrics object is initialized correctly."""
17+ metrics = Metrics (fake_api_call )
18+
19+ assert_match_object (metrics .api_call , fake_api_call )
20+ assert_object_lists_match (
21+ metrics .api_call .node_manager .nodes ,
22+ fake_api_call .node_manager .nodes ,
23+ )
24+ assert_match_object (
25+ metrics .api_call .config .nearest_node ,
26+ fake_api_call .config .nearest_node ,
27+ )
28+ assert metrics .resource_path == "/metrics.json" # noqa: WPS437
29+
30+
31+ def test_init_async (fake_async_api_call : AsyncApiCall ) -> None :
32+ """Test that the AsyncMetrics object is initialized correctly."""
33+ metrics = AsyncMetrics (fake_async_api_call )
34+
35+ assert_match_object (metrics .api_call , fake_async_api_call )
36+ assert_object_lists_match (
37+ metrics .api_call .node_manager .nodes ,
38+ fake_async_api_call .node_manager .nodes ,
39+ )
40+ assert_match_object (
41+ metrics .api_call .config .nearest_node ,
42+ fake_async_api_call .config .nearest_node ,
43+ )
44+ assert metrics .resource_path == "/metrics.json" # noqa: WPS437
45+
46+
847def test_actual_retrieve (actual_metrics : Metrics ) -> None :
9- """Test that the Debug object can retrieve a debug on Typesense server and verify response structure."""
48+ """Test that the Metrics object can retrieve metrics on Typesense server and verify response structure."""
1049 response = actual_metrics .retrieve ()
1150
1251 assert "system_cpu_active_percentage" in response
@@ -24,3 +63,24 @@ def test_actual_retrieve(actual_metrics: Metrics) -> None:
2463 assert "typesense_memory_metadata_bytes" in response
2564 assert "typesense_memory_resident_bytes" in response
2665 assert "typesense_memory_retained_bytes" in response
66+
67+
68+ async def test_actual_retrieve_async (actual_async_metrics : AsyncMetrics ) -> None :
69+ """Test that the AsyncMetrics object can retrieve metrics on Typesense server and verify response structure."""
70+ response = await actual_async_metrics .retrieve ()
71+
72+ assert "system_cpu_active_percentage" in response
73+ assert "system_disk_total_bytes" in response
74+ assert "system_disk_used_bytes" in response
75+ assert "system_memory_total_bytes" in response
76+ assert "system_memory_used_bytes" in response
77+ assert "system_network_received_bytes" in response
78+ assert "system_network_sent_bytes" in response
79+ assert "typesense_memory_active_bytes" in response
80+ assert "typesense_memory_allocated_bytes" in response
81+ assert "typesense_memory_fragmentation_ratio" in response
82+
83+ assert "typesense_memory_mapped_bytes" in response
84+ assert "typesense_memory_metadata_bytes" in response
85+ assert "typesense_memory_resident_bytes" in response
86+ assert "typesense_memory_retained_bytes" in response
0 commit comments