conductor(checkpoint): Checkpoint end of Phase 3
This commit is contained in:
46
scripts/cluster_status/tests/test_aggregator.py
Normal file
46
scripts/cluster_status/tests/test_aggregator.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
import cluster_aggregator
|
||||
|
||||
@patch("consul_client.get_cluster_services")
|
||||
@patch("litefs_client.get_node_status")
|
||||
def test_aggregate_cluster_status(mock_litefs, mock_consul):
|
||||
"""Test aggregating Consul and LiteFS data."""
|
||||
# Mock Consul data
|
||||
mock_consul.return_value = [
|
||||
{"node": "node1", "address": "1.1.1.1", "role": "primary", "status": "passing"},
|
||||
{"node": "node2", "address": "1.1.1.2", "role": "replica", "status": "passing"}
|
||||
]
|
||||
|
||||
# Mock LiteFS data
|
||||
def litefs_side_effect(addr):
|
||||
if addr == "1.1.1.1":
|
||||
return {"is_primary": True, "uptime": 100, "advertise_url": "url1"}
|
||||
return {"is_primary": False, "uptime": 50, "advertise_url": "url2", "replication_lag": 10}
|
||||
|
||||
mock_litefs.side_effect = litefs_side_effect
|
||||
|
||||
cluster_data = cluster_aggregator.get_cluster_status("http://consul:8500")
|
||||
|
||||
assert cluster_data["health"] == "Healthy"
|
||||
assert len(cluster_data["nodes"]) == 2
|
||||
|
||||
node1 = next(n for n in cluster_data["nodes"] if n["node"] == "node1")
|
||||
assert node1["litefs_primary"] is True
|
||||
assert node1["role"] == "primary"
|
||||
|
||||
node2 = next(n for n in cluster_data["nodes"] if n["node"] == "node2")
|
||||
assert node2["litefs_primary"] is False
|
||||
assert node2["replication_lag"] == 10
|
||||
|
||||
@patch("consul_client.get_cluster_services")
|
||||
@patch("litefs_client.get_node_status")
|
||||
def test_aggregate_cluster_status_unhealthy(mock_litefs, mock_consul):
|
||||
"""Test health calculation when nodes are critical."""
|
||||
mock_consul.return_value = [
|
||||
{"node": "node1", "address": "1.1.1.1", "role": "primary", "status": "critical"}
|
||||
]
|
||||
mock_litefs.return_value = {"is_primary": True, "uptime": 100}
|
||||
|
||||
cluster_data = cluster_aggregator.get_cluster_status("http://consul:8500")
|
||||
assert cluster_data["health"] == "Unhealthy"
|
||||
Reference in New Issue
Block a user