ClickHouse/tests/integration/test_keeper_http_control/test.py

75 lines
2.4 KiB
Python
Raw Normal View History

2023-12-07 06:28:41 +00:00
#!/usr/bin/env python3
import os
import pytest
import requests
from helpers.cluster import ClickHouseCluster
2023-12-12 10:35:17 +00:00
from helpers.network import PartitionManager
import helpers.keeper_utils as keeper_utils
2023-12-07 06:28:41 +00:00
cluster = ClickHouseCluster(__file__)
CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")
node1 = cluster.add_instance(
"node1", main_configs=["configs/enable_keeper1.xml"], stay_alive=True
)
node2 = cluster.add_instance(
"node2", main_configs=["configs/enable_keeper2.xml"], stay_alive=True
)
node3 = cluster.add_instance(
"node3", main_configs=["configs/enable_keeper3.xml"], stay_alive=True
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2023-12-12 10:44:55 +00:00
2023-12-12 10:35:17 +00:00
def test_http_readiness_basic_responses(started_cluster):
2023-12-07 06:28:41 +00:00
leader = keeper_utils.get_leader(cluster, [node1, node2, node3])
response = requests.get(
2023-12-07 06:49:10 +00:00
"http://{host}:{port}/ready".format(host=leader.ip_address, port=9182)
2023-12-07 06:28:41 +00:00
)
2023-12-07 06:49:10 +00:00
assert response.status_code == 200
2023-12-07 06:28:41 +00:00
readiness_data = response.json()
2023-12-07 06:49:10 +00:00
assert readiness_data["status"] == "ok"
2023-12-12 10:35:17 +00:00
assert readiness_data["details"]["role"] == "leader"
2023-12-07 06:28:41 +00:00
2023-12-12 08:32:16 +00:00
follower = keeper_utils.get_any_follower(cluster, [node1, node2, node3])
2023-12-07 06:28:41 +00:00
response = requests.get(
2023-12-07 06:49:10 +00:00
"http://{host}:{port}/ready".format(host=follower.ip_address, port=9182)
2023-12-07 06:28:41 +00:00
)
2023-12-07 06:49:10 +00:00
assert response.status_code == 200
2023-12-07 06:28:41 +00:00
readiness_data = response.json()
2023-12-07 06:49:10 +00:00
assert readiness_data["status"] == "ok"
2023-12-12 10:35:17 +00:00
assert readiness_data["details"]["role"] == "follower"
assert readiness_data["details"]["hasLeader"] == True
2023-12-12 10:44:55 +00:00
2023-12-12 10:35:17 +00:00
def test_http_readiness_partitioned_cluster(started_cluster):
with PartitionManager() as pm:
leader = keeper_utils.get_leader(cluster, [node1, node2, node3])
follower = keeper_utils.get_any_follower(cluster, [node1, node2, node3])
2023-12-12 10:44:55 +00:00
pm.partition_instances(leader, follower)
2023-12-12 11:27:49 +00:00
keeper_utils.wait_until_quorum_lost(cluster, follower)
2023-12-12 10:35:17 +00:00
response = requests.get(
"http://{host}:{port}/ready".format(host=follower.ip_address, port=9182)
)
print(response.json())
assert response.status_code == 503
readiness_data = response.json()
assert readiness_data["status"] == "fail"
assert readiness_data["details"]["role"] == "follower"
assert readiness_data["details"]["hasLeader"] == False