mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
The initial cleanup (TRUNCATE/DROP) was insufficient because tests also
modify config files and server state that persists across re-runs:
- `test_replication_credentials`: `test_different_credentials` and
`test_credentials_and_no_credentials` modify `credentials1.xml` via
`replace_config`. On re-run the modified config persists, changing
replication behavior. Fix: restore original credentials config and
`SYSTEM RELOAD CONFIG` at the start of each test. Also use
`CREATE DATABASE/TABLE IF NOT EXISTS` in `_fill_nodes`.
- `test_group_array_element_size`: `test_max_exement_size` ends with
config at `11` instead of `10`, so on re-run `replace_in_config("10",
"11")` is a no-op and assertions fail. Fix: restore original config
via `replace_config` + `restart_clickhouse` at test start.
- `test_version_update`: use `DROP TABLE IF EXISTS test SYNC` to ensure
ZooKeeper metadata is cleaned up for the `ReplicatedReplacingMergeTree`.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
import pytest
|
|
|
|
from helpers.cluster import CLICKHOUSE_CI_MIN_TESTED_VERSION, ClickHouseCluster
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
node1 = cluster.add_instance("node1", stay_alive=True)
|
|
|
|
node2 = cluster.add_instance(
|
|
"node2",
|
|
with_zookeeper=True,
|
|
image="clickhouse/clickhouse-server",
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
|
with_installed_binary=True,
|
|
stay_alive=True,
|
|
)
|
|
|
|
|
|
def insert_data(node, table_name="test_table", n=1, col2=1):
|
|
node.query(
|
|
""" INSERT INTO {}
|
|
SELECT toDateTime(NOW()), {},
|
|
sumMapState(arrayMap(i -> 1, range(300)), arrayMap(i -> 1, range(300)))
|
|
FROM numbers({});""".format(
|
|
table_name, col2, n
|
|
)
|
|
)
|
|
|
|
|
|
def create_table(node, name="test_table", version=None):
|
|
node.query("DROP TABLE IF EXISTS {};".format(name))
|
|
if version is None:
|
|
node.query(
|
|
"""
|
|
CREATE TABLE {}
|
|
(
|
|
`col1` DateTime,
|
|
`col2` Int64,
|
|
`col3` AggregateFunction(sumMap, Array(UInt8), Array(UInt8))
|
|
)
|
|
ENGINE = AggregatingMergeTree() ORDER BY (col1, col2) """.format(
|
|
name
|
|
)
|
|
)
|
|
else:
|
|
node.query(
|
|
"""
|
|
CREATE TABLE {}
|
|
(
|
|
`col1` DateTime,
|
|
`col2` Int64,
|
|
`col3` AggregateFunction({}, sumMap, Array(UInt8), Array(UInt8))
|
|
)
|
|
ENGINE = AggregatingMergeTree() ORDER BY (col1, col2) """.format(
|
|
name, version
|
|
)
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def start_cluster():
|
|
try:
|
|
cluster.start()
|
|
yield cluster
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
|
|
def test_modulo_partition_key_issue_23508(start_cluster):
|
|
node2.query("DROP TABLE IF EXISTS test SYNC")
|
|
node2.query(
|
|
"CREATE TABLE test (id Int64, v UInt64, value String) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/table1', '1', v) PARTITION BY id % 20 ORDER BY (id, v)"
|
|
)
|
|
node2.query(
|
|
"INSERT INTO test SELECT number, number, toString(number) FROM numbers(10)"
|
|
)
|
|
|
|
expected = node2.query("SELECT number, number, toString(number) FROM numbers(10)")
|
|
partition_data = node2.query(
|
|
"SELECT partition, name FROM system.parts WHERE table='test' ORDER BY partition"
|
|
)
|
|
assert expected == node2.query("SELECT * FROM test ORDER BY id")
|
|
|
|
node2.restart_with_latest_version()
|
|
|
|
assert expected == node2.query("SELECT * FROM test ORDER BY id")
|
|
assert partition_data == node2.query(
|
|
"SELECT partition, name FROM system.parts WHERE table='test' ORDER BY partition"
|
|
)
|