2021-08-30 09:53:56 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
2022-07-18 12:25:14 +00:00
|
|
|
cluster = ClickHouseCluster(__file__)
|
2022-03-22 16:39:58 +00:00
|
|
|
node1 = cluster.add_instance("node1", with_zookeeper=False)
|
|
|
|
node2 = cluster.add_instance("node2", with_zookeeper=False)
|
2021-08-30 09:53:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
def test_log_quries_probability_one(start_cluster):
|
|
|
|
for i in range(100):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query("SELECT 12345", settings={"log_queries_probability": 0.5})
|
2021-08-30 09:53:56 +00:00
|
|
|
|
|
|
|
node1.query("SYSTEM FLUSH LOGS")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
node1.query(
|
|
|
|
"SELECT count() < (2 * 100) FROM system.query_log WHERE query LIKE '%12345%' AND query NOT LIKE '%system.query_log%'"
|
|
|
|
)
|
|
|
|
== "1\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
node1.query(
|
|
|
|
"SELECT count() > 0 FROM system.query_log WHERE query LIKE '%12345%' AND query NOT LIKE '%system.query_log%'"
|
|
|
|
)
|
|
|
|
== "1\n"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
node1.query(
|
|
|
|
"SELECT count() % 2 FROM system.query_log WHERE query LIKE '%12345%' AND query NOT LIKE '%system.query_log%'"
|
|
|
|
)
|
|
|
|
== "0\n"
|
|
|
|
)
|
2021-08-30 09:53:56 +00:00
|
|
|
|
|
|
|
node1.query("TRUNCATE TABLE system.query_log")
|
|
|
|
|
|
|
|
|
|
|
|
def test_log_quries_probability_two(start_cluster):
|
|
|
|
for i in range(100):
|
2022-03-22 16:39:58 +00:00
|
|
|
node1.query(
|
|
|
|
"SELECT 12345 FROM remote('node2', system, one)",
|
|
|
|
settings={"log_queries_probability": 0.5},
|
|
|
|
)
|
2021-08-30 09:53:56 +00:00
|
|
|
|
|
|
|
node1.query("SYSTEM FLUSH LOGS")
|
|
|
|
node2.query("SYSTEM FLUSH LOGS")
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
ans1 = node1.query(
|
|
|
|
"SELECT count() FROM system.query_log WHERE query LIKE '%12345%' AND query NOT LIKE '%system.query_log%'"
|
|
|
|
)
|
|
|
|
ans2 = node2.query(
|
|
|
|
"SELECT count() FROM system.query_log WHERE query LIKE '%12345%' AND query NOT LIKE '%system.query_log%'"
|
|
|
|
)
|
2021-08-30 09:53:56 +00:00
|
|
|
|
|
|
|
assert ans1 == ans2
|
|
|
|
|
|
|
|
node1.query("TRUNCATE TABLE system.query_log")
|
|
|
|
node2.query("TRUNCATE TABLE system.query_log")
|