mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
adjust tests
This commit is contained in:
parent
e3290c7820
commit
633f700df6
@ -12,18 +12,6 @@ node = cluster.add_instance(
|
||||
stay_alive=True,
|
||||
)
|
||||
|
||||
system_logs = [
|
||||
# enabled by default
|
||||
("system.text_log", 1),
|
||||
("system.query_log", 1),
|
||||
("system.query_thread_log", 1),
|
||||
("system.part_log", 1),
|
||||
("system.trace_log", 1),
|
||||
("system.metric_log", 1),
|
||||
("system.error_log", 1),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def start_cluster():
|
||||
try:
|
||||
@ -33,22 +21,29 @@ def start_cluster():
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def flush_logs():
|
||||
def test_system_logs_exists():
|
||||
system_logs = [
|
||||
# disabled by default
|
||||
("system.text_log", 0),
|
||||
("system.query_log", 1),
|
||||
("system.query_thread_log", 1),
|
||||
("system.part_log", 1),
|
||||
("system.trace_log", 1),
|
||||
("system.metric_log", 1),
|
||||
("system.error_log", 1),
|
||||
]
|
||||
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,exists", system_logs)
|
||||
def test_system_logs(flush_logs, table, exists):
|
||||
q = "SELECT * FROM {}".format(table)
|
||||
if exists:
|
||||
node.query(q)
|
||||
else:
|
||||
response = node.query_and_get_error(q)
|
||||
assert (
|
||||
"Table {} does not exist".format(table) in response
|
||||
or "Unknown table expression identifier '{}'".format(table) in response
|
||||
)
|
||||
for table, exists in system_logs:
|
||||
q = "SELECT * FROM {}".format(table)
|
||||
if exists:
|
||||
node.query(q)
|
||||
else:
|
||||
response = node.query_and_get_error(q)
|
||||
assert (
|
||||
"Table {} does not exist".format(table) in response
|
||||
or "Unknown table expression identifier '{}'".format(table) in response
|
||||
)
|
||||
|
||||
|
||||
# Logic is tricky, let's check that there is no hang in case of message queue
|
||||
@ -67,11 +62,14 @@ def test_system_logs_non_empty_queue():
|
||||
|
||||
|
||||
def test_system_suspend():
|
||||
node.query("CREATE TABLE t (x DateTime) ENGINE=Memory;")
|
||||
node.query("INSERT INTO t VALUES (now());")
|
||||
node.query("SYSTEM SUSPEND FOR 1 SECOND;")
|
||||
node.query("INSERT INTO t VALUES (now());")
|
||||
assert "1\n" == node.query("SELECT max(x) - min(x) >= 1 FROM t;")
|
||||
try:
|
||||
node.query("CREATE TABLE t (x DateTime) ENGINE=Memory;")
|
||||
node.query("INSERT INTO t VALUES (now());")
|
||||
node.query("SYSTEM SUSPEND FOR 1 SECOND;")
|
||||
node.query("INSERT INTO t VALUES (now());")
|
||||
assert "1\n" == node.query("SELECT max(x) - min(x) >= 1 FROM t;")
|
||||
finally:
|
||||
node.query("DROP TABLE IF EXISTS t;")
|
||||
|
||||
|
||||
def test_log_max_size(start_cluster):
|
||||
@ -95,6 +93,7 @@ def test_log_max_size(start_cluster):
|
||||
]
|
||||
)
|
||||
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
node.query(f"TRUNCATE TABLE IF EXISTS system.query_log")
|
||||
node.restart_clickhouse()
|
||||
|
||||
|
@ -33,124 +33,129 @@ def test_system_logs_recreate():
|
||||
"error_log",
|
||||
]
|
||||
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert "ENGINE = Null" not in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
try:
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert "ENGINE = Null" not in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
== 1
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
# NOTE: we use zzz- prefix to make it the last file,
|
||||
# so that it will be applied last.
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
f"""echo "
|
||||
<clickhouse>
|
||||
<{table}>
|
||||
<engine>ENGINE = Null</engine>
|
||||
<partition_by remove='remove'/>
|
||||
</{table}>
|
||||
</clickhouse>
|
||||
" > /etc/clickhouse-server/config.d/zzz-override-{table}.xml
|
||||
""",
|
||||
]
|
||||
)
|
||||
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" not in node.query(
|
||||
f"SHOW CREATE TABLE system.{table}"
|
||||
)
|
||||
assert "ENGINE = Null" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
# NOTE: we use zzz- prefix to make it the last file,
|
||||
# so that it will be applied last.
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
f"""echo "
|
||||
<clickhouse>
|
||||
<{table}>
|
||||
<engine>ENGINE = Null</engine>
|
||||
<partition_by remove='remove'/>
|
||||
</{table}>
|
||||
</clickhouse>
|
||||
" > /etc/clickhouse-server/config.d/zzz-override-{table}.xml
|
||||
""",
|
||||
]
|
||||
)
|
||||
== 2
|
||||
)
|
||||
|
||||
# apply only storage_policy for all system tables
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
f"""echo "
|
||||
<clickhouse>
|
||||
<{table}>
|
||||
<storage_policy>system_tables</storage_policy>
|
||||
</{table}>
|
||||
</clickhouse>
|
||||
" > /etc/clickhouse-server/config.d/zzz-override-{table}.xml
|
||||
""",
|
||||
]
|
||||
)
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
import logging
|
||||
|
||||
for table in system_logs:
|
||||
create_table_sql = node.query(f"SHOW CREATE TABLE system.{table} FORMAT TSVRaw")
|
||||
logging.debug(
|
||||
"With storage policy, SHOW CREATE TABLE system.%s is: %s",
|
||||
table,
|
||||
create_table_sql,
|
||||
)
|
||||
assert "ENGINE = MergeTree" in create_table_sql
|
||||
assert "ENGINE = Null" not in create_table_sql
|
||||
assert "SETTINGS storage_policy = 'system_tables'" in create_table_sql
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" not in node.query(
|
||||
f"SHOW CREATE TABLE system.{table}"
|
||||
)
|
||||
== 3
|
||||
)
|
||||
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
["rm", f"/etc/clickhouse-server/config.d/zzz-override-{table}.xml"]
|
||||
)
|
||||
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert "ENGINE = Null" not in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
assert "ENGINE = Null" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
== 2
|
||||
)
|
||||
== 4
|
||||
)
|
||||
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
# Ensure that there was no superfluous RENAME's
|
||||
# IOW that the table created only when the structure is indeed different.
|
||||
for table in system_logs:
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
# apply only storage_policy for all system tables
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
f"""echo "
|
||||
<clickhouse>
|
||||
<{table}>
|
||||
<storage_policy>system_tables</storage_policy>
|
||||
</{table}>
|
||||
</clickhouse>
|
||||
" > /etc/clickhouse-server/config.d/zzz-override-{table}.xml
|
||||
""",
|
||||
]
|
||||
)
|
||||
== 4
|
||||
)
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
import logging
|
||||
|
||||
for table in system_logs:
|
||||
create_table_sql = node.query(f"SHOW CREATE TABLE system.{table} FORMAT TSVRaw")
|
||||
logging.debug(
|
||||
"With storage policy, SHOW CREATE TABLE system.%s is: %s",
|
||||
table,
|
||||
create_table_sql,
|
||||
)
|
||||
assert "ENGINE = MergeTree" in create_table_sql
|
||||
assert "ENGINE = Null" not in create_table_sql
|
||||
assert "SETTINGS storage_policy = 'system_tables'" in create_table_sql
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
== 3
|
||||
)
|
||||
|
||||
for table in system_logs:
|
||||
node.exec_in_container(
|
||||
["rm", f"/etc/clickhouse-server/config.d/zzz-override-{table}.xml"]
|
||||
)
|
||||
|
||||
node.restart_clickhouse()
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
for table in system_logs:
|
||||
assert "ENGINE = MergeTree" in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert "ENGINE = Null" not in node.query(f"SHOW CREATE TABLE system.{table}")
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
== 4
|
||||
)
|
||||
|
||||
node.query("SYSTEM FLUSH LOGS")
|
||||
# Ensure that there was no superfluous RENAME's
|
||||
# IOW that the table created only when the structure is indeed different.
|
||||
for table in system_logs:
|
||||
assert (
|
||||
len(
|
||||
node.query(f"SHOW TABLES FROM system LIKE '{table}%'")
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
== 4
|
||||
)
|
||||
finally:
|
||||
for table in system_logs:
|
||||
for syffix in range(3):
|
||||
node.query(f"DROP TABLE IF EXISTS system.{table}_{syffix} sync")
|
||||
|
||||
|
||||
def test_drop_system_log():
|
||||
|
Loading…
Reference in New Issue
Block a user