SIENTIAPDE-1174
Refactor unit tests to improve readability and maintainability - Updated test assertions and mock setups in test_app.py for clarity. - Added 'pod_id' to the metadata in test_ingestor.py for consistency. - Introduced a new test for TAG_WRITTEN_COUNT in test_metrics.py to verify its definition. - Enhanced test data structure in test_data_manager.py to include additional fields.
This commit is contained in:
@@ -7,6 +7,15 @@ import ingestor.metrics as metrics
|
||||
# --- Test Functions for Each Metric (Corrected for v0.22.0 _name behavior) ---
|
||||
|
||||
|
||||
def test_ingestor_tag_written_count():
|
||||
"""Verify the definition of INGESTOR_TAG_WRITTEN_COUNT."""
|
||||
assert metrics.TAG_WRITTEN_COUNT is not None
|
||||
assert isinstance(metrics.TAG_WRITTEN_COUNT, Counter)
|
||||
assert metrics.TAG_WRITTEN_COUNT._name == "ingestor_tag_written_count"
|
||||
assert set(metrics.TAG_WRITTEN_COUNT._labelnames) == {
|
||||
"pod_id", "tag_name", "collection_name"}
|
||||
|
||||
|
||||
def test_app_loop_count():
|
||||
"""Verify the definition of APP_LOOP_COUNT."""
|
||||
assert metrics.APP_LOOP_COUNT is not None
|
||||
@@ -118,7 +127,8 @@ def test_opc_connections_total():
|
||||
assert (
|
||||
metrics.OPC_CONNECTIONS_TOTAL._name == "opc_connections_initiated"
|
||||
) # REMOVED _total
|
||||
assert set(metrics.OPC_CONNECTIONS_TOTAL._labelnames) == {"pod_id", "server_name"}
|
||||
assert set(metrics.OPC_CONNECTIONS_TOTAL._labelnames) == {
|
||||
"pod_id", "server_name"}
|
||||
|
||||
|
||||
def test_opc_connections_failed():
|
||||
@@ -128,7 +138,8 @@ def test_opc_connections_failed():
|
||||
assert (
|
||||
metrics.OPC_CONNECTIONS_FAILED._name == "opc_connections_failed"
|
||||
) # REMOVED _total
|
||||
assert set(metrics.OPC_CONNECTIONS_FAILED._labelnames) == {"pod_id", "server_name"}
|
||||
assert set(metrics.OPC_CONNECTIONS_FAILED._labelnames) == {
|
||||
"pod_id", "server_name"}
|
||||
|
||||
|
||||
def test_opc_connection_status():
|
||||
@@ -162,7 +173,8 @@ def test_opc_tags_subscribed():
|
||||
assert metrics.OPC_TAGS_SUBSCRIBED is not None
|
||||
assert isinstance(metrics.OPC_TAGS_SUBSCRIBED, Gauge)
|
||||
assert metrics.OPC_TAGS_SUBSCRIBED._name == "opc_tags_subscribed_current"
|
||||
assert set(metrics.OPC_TAGS_SUBSCRIBED._labelnames) == {"pod_id", "server_name"}
|
||||
assert set(metrics.OPC_TAGS_SUBSCRIBED._labelnames) == {
|
||||
"pod_id", "server_name"}
|
||||
|
||||
|
||||
def test_opc_cycles_without_data():
|
||||
@@ -170,7 +182,8 @@ def test_opc_cycles_without_data():
|
||||
assert metrics.OPC_CYCLES_WITHOUT_DATA is not None
|
||||
assert isinstance(metrics.OPC_CYCLES_WITHOUT_DATA, Gauge)
|
||||
assert metrics.OPC_CYCLES_WITHOUT_DATA._name == "opc_cycles_without_data"
|
||||
assert set(metrics.OPC_CYCLES_WITHOUT_DATA._labelnames) == {"pod_id", "server_name"}
|
||||
assert set(metrics.OPC_CYCLES_WITHOUT_DATA._labelnames) == {
|
||||
"pod_id", "server_name"}
|
||||
|
||||
|
||||
def test_opc_reconnections_total():
|
||||
@@ -180,7 +193,8 @@ def test_opc_reconnections_total():
|
||||
assert (
|
||||
metrics.OPC_RECONNECTIONS_TOTAL._name == "opc_reconnections_tried"
|
||||
) # REMOVED _total
|
||||
assert set(metrics.OPC_RECONNECTIONS_TOTAL._labelnames) == {"pod_id", "server_name"}
|
||||
assert set(metrics.OPC_RECONNECTIONS_TOTAL._labelnames) == {
|
||||
"pod_id", "server_name"}
|
||||
|
||||
|
||||
def test_kafka_messages_sent():
|
||||
@@ -198,7 +212,8 @@ def test_kafka_messages_errors():
|
||||
assert (
|
||||
metrics.KAFKA_MESSAGES_ERRORS._name == "kafka_messages_errors"
|
||||
) # REMOVED _total
|
||||
assert set(metrics.KAFKA_MESSAGES_ERRORS._labelnames) == {"pod_id", "topic"}
|
||||
assert set(metrics.KAFKA_MESSAGES_ERRORS._labelnames) == {
|
||||
"pod_id", "topic"}
|
||||
|
||||
|
||||
def test_kafka_connection_status():
|
||||
@@ -214,7 +229,8 @@ def test_redis_operations_total():
|
||||
assert metrics.REDIS_OPERATIONS_TOTAL is not None
|
||||
assert isinstance(metrics.REDIS_OPERATIONS_TOTAL, Counter)
|
||||
assert metrics.REDIS_OPERATIONS_TOTAL._name == "redis_operations" # REMOVED _total
|
||||
assert set(metrics.REDIS_OPERATIONS_TOTAL._labelnames) == {"pod_id", "operation"}
|
||||
assert set(metrics.REDIS_OPERATIONS_TOTAL._labelnames) == {
|
||||
"pod_id", "operation"}
|
||||
|
||||
|
||||
def test_redis_operations_errors():
|
||||
@@ -224,7 +240,8 @@ def test_redis_operations_errors():
|
||||
assert (
|
||||
metrics.REDIS_OPERATIONS_ERRORS._name == "redis_operations_errors"
|
||||
) # REMOVED _total
|
||||
assert set(metrics.REDIS_OPERATIONS_ERRORS._labelnames) == {"pod_id", "operation"}
|
||||
assert set(metrics.REDIS_OPERATIONS_ERRORS._labelnames) == {
|
||||
"pod_id", "operation"}
|
||||
|
||||
|
||||
def test_redis_operations_duration():
|
||||
@@ -234,7 +251,8 @@ def test_redis_operations_duration():
|
||||
assert (
|
||||
metrics.REDIS_OPERATIONS_DURATION._name == "redis_operations_duration_seconds"
|
||||
)
|
||||
assert set(metrics.REDIS_OPERATIONS_DURATION._labelnames) == {"pod_id", "operation"}
|
||||
assert set(metrics.REDIS_OPERATIONS_DURATION._labelnames) == {
|
||||
"pod_id", "operation"}
|
||||
|
||||
|
||||
def test_redis_connection_status():
|
||||
@@ -250,4 +268,5 @@ def test_notifications_sent():
|
||||
assert metrics.NOTIFICATIONS_SENT is not None
|
||||
assert isinstance(metrics.NOTIFICATIONS_SENT, Counter)
|
||||
assert metrics.NOTIFICATIONS_SENT._name == "notifications_sent" # REMOVED _total
|
||||
assert set(metrics.NOTIFICATIONS_SENT._labelnames) == {"pod_id", "level", "block"}
|
||||
assert set(metrics.NOTIFICATIONS_SENT._labelnames) == {
|
||||
"pod_id", "level", "block"}
|
||||
|
||||
Reference in New Issue
Block a user