ClickHouse/tests/integration/test_shutdown_wait_unfinished_queries/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.0 KiB
Python
Raw Normal View History

import pytest
import threading
import time
2023-08-23 06:05:26 +00:00
import uuid
from helpers.cluster import ClickHouseCluster
2023-08-23 06:05:26 +00:00
from helpers.test_tools import assert_eq_with_retry
cluster = ClickHouseCluster(__file__)
node_wait_queries = cluster.add_instance(
2023-07-18 20:23:55 +00:00
"node_wait_queries",
main_configs=["configs/config_wait.xml"],
user_configs=["configs/users.xml"],
stay_alive=True,
)
node_kill_queries = cluster.add_instance(
2023-07-18 20:23:55 +00:00
"node_kill_queries",
main_configs=["configs/config_kill.xml"],
user_configs=["configs/users.xml"],
stay_alive=True,
)
global result
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2023-08-23 06:05:26 +00:00
def do_long_query(node, query_id):
global result
result = node.query_and_get_answer_with_error(
"SELECT sleepEachRow(1) FROM system.numbers LIMIT 10",
settings={"send_logs_level": "trace"},
2023-08-23 06:05:26 +00:00
query_id=query_id,
)
def test_shutdown_wait_unfinished_queries(start_cluster):
global result
2023-08-23 06:05:26 +00:00
query_id = uuid.uuid4().hex
2023-08-23 06:27:28 +00:00
long_query = threading.Thread(
target=do_long_query,
args=(
node_wait_queries,
query_id,
),
)
long_query.start()
2023-08-23 06:27:28 +00:00
assert_eq_with_retry(
node_wait_queries,
f"SELECT query_id FROM system.processes WHERE query_id = '{query_id}'",
query_id,
)
node_wait_queries.stop_clickhouse(kill=False)
long_query.join()
assert result[0].count("0") == 10
2023-08-23 06:05:26 +00:00
query_id = uuid.uuid4().hex
2023-08-23 06:27:28 +00:00
long_query = threading.Thread(
target=do_long_query,
args=(
node_kill_queries,
query_id,
),
)
long_query.start()
2023-08-23 06:27:28 +00:00
assert_eq_with_retry(
node_kill_queries,
f"SELECT query_id FROM system.processes WHERE query_id = '{query_id}'",
query_id,
)
node_kill_queries.stop_clickhouse(kill=False)
long_query.join()
assert "QUERY_WAS_CANCELLED" in result[1]