separate integration tests for keeper-client

This commit is contained in:
pufit 2023-03-16 15:37:06 -04:00 committed by Nikita Mikhaylov
parent ef9f66e36f
commit 65f2516079
4 changed files with 78 additions and 10 deletions

View File

@ -1,18 +1,26 @@
import socket import socket
import time import time
from helper.client import CommandRequest
def get_keeper_socket(cluster, node, port=9181):
hosts = cluster.get_instance_ip(node.name)
client = socket.socket()
client.settimeout(10)
client.connect((hosts, port))
return client
def send_4lw_cmd(cluster, node, cmd="ruok", port=9181): def send_4lw_cmd(cluster, node, cmd="ruok", port=9181):
return CommandRequest( client = None
[ try:
"cluster.server_bin_path", client = get_keeper_socket(cluster, node, port)
"keeper-client", client.send(cmd.encode())
f"{cluster.get_instance_ip(node.name)}:{port}", data = client.recv(100_000)
"-q", data = data.decode()
cmd, return data
] finally:
).get_answer() if client is not None:
client.close()
NOT_SERVING_REQUESTS_ERROR_MSG = "This instance is not currently serving requests" NOT_SERVING_REQUESTS_ERROR_MSG = "This instance is not currently serving requests"

View File

@ -0,0 +1,3 @@
<clickhouse>
</clickhouse>

View File

@ -0,0 +1,57 @@
import pytest
from helpers.client import CommandRequest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
main_configs=["configs/keeper_config.xml"],
with_zookeeper=True,
stay_alive=True,
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_base_commands(started_cluster):
_ = started_cluster
command = CommandRequest(
[
started_cluster.server_bin_path,
"keeper-client",
f"{cluster.get_instance_ip('zoo1')}:{cluster.zookeeper_port}",
"-q",
"create test_create_zk_node1 testvalue1;create test_create_zk_node_2 testvalue2;get test_create_zk_node1;",
],
stdin="",
)
assert command.get_answer() == "testvalue1\n"
def test_four_letter_word_commands(started_cluster):
_ = started_cluster
command = CommandRequest(
[
started_cluster.server_bin_path,
"keeper-client",
f"{cluster.get_instance_ip('zoo1')}:{cluster.zookeeper_port}",
"-q",
"ruok",
],
stdin="",
)
assert command.get_answer() == "imok\n"