Add integration test for checking new build_id column in trace_log plus the table renaming behavior upon binary changes.

This commit is contained in:
woodlzm 2024-05-10 23:30:48 -07:00
parent 77a8a0ce98
commit 7d809cbe9b
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,69 @@
import pytest
from helpers.cluster import ClickHouseCluster, CLICKHOUSE_CI_MIN_TESTED_VERSION
TEST_QUERY_ID = "test_trace_log_build_id_query_{}"
OLD_TEST_QUERY_ID = TEST_QUERY_ID.format('0')
NEW_TEST_QUERY_ID = TEST_QUERY_ID.format('1')
ACTIVE_TRACE_LOG_TABLE = "trace_log"
RENAMED_TRACE_LOG_TABLE = "trace_log_0"
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
with_zookeeper=True,
image="clickhouse/clickhouse-server",
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
stay_alive=True,
with_installed_binary=True,
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
except Exception as ex:
print(ex)
finally:
cluster.shutdown()
def test_trace_log_build_id(started_cluster):
# This test checks that build_id column of system_log.trace_log is non-empty, and gets renamed when binary version changes.
# We make queries to create entries in trace_log, then restart with new version and verify if the old
# trace_log table is renamed and a new trace_log table is created.
query_for_table_name = "EXISTS TABLE system.{table}"
node.query(
"SELECT sleep(1)",
query_id=OLD_TEST_QUERY_ID,
)
node.query("SYSTEM FLUSH LOGS")
assert node.query(query_for_table_name.format(table=ACTIVE_TRACE_LOG_TABLE)) == "1\n"
assert node.query(query_for_table_name.format(table=RENAMED_TRACE_LOG_TABLE)) == "0\n"
node.restart_with_latest_version()
query_for_test_query_id = """
SELECT EXISTS
(
SELECT *
FROM system.{table}
WHERE query_id = \'{query_id}\'
)
"""
node.query(
"SELECT sleep(1)",
query_id=NEW_TEST_QUERY_ID,
)
node.query("SYSTEM FLUSH LOGS")
assert node.query(query_for_test_query_id.format(table=ACTIVE_TRACE_LOG_TABLE, query_id=OLD_TEST_QUERY_ID)) == "0\n"
assert node.query(query_for_test_query_id.format(table=ACTIVE_TRACE_LOG_TABLE, query_id=NEW_TEST_QUERY_ID)) == "1\n"
assert node.query(query_for_test_query_id.format(table=RENAMED_TRACE_LOG_TABLE, query_id=OLD_TEST_QUERY_ID)) == "1\n"