From 7d809cbe9bb25cf292faf5a314614d45f0c4b6de Mon Sep 17 00:00:00 2001 From: woodlzm Date: Fri, 10 May 2024 23:30:48 -0700 Subject: [PATCH] Add integration test for checking new build_id column in trace_log plus the table renaming behavior upon binary changes. --- .../test_trace_log_build_id/__init__.py | 0 .../test_trace_log_build_id/test.py | 69 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/integration/test_trace_log_build_id/__init__.py create mode 100644 tests/integration/test_trace_log_build_id/test.py diff --git a/tests/integration/test_trace_log_build_id/__init__.py b/tests/integration/test_trace_log_build_id/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_trace_log_build_id/test.py b/tests/integration/test_trace_log_build_id/test.py new file mode 100644 index 00000000000..b4a49b2e4d3 --- /dev/null +++ b/tests/integration/test_trace_log_build_id/test.py @@ -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" +