Skip to content

Commit

Permalink
clickhouse: Fix insertion race condition in test
Browse files Browse the repository at this point in the history
This commit makes replicas in Clickhouse tests synchronize before
checking if expected data is present. It eliminates situation when
one replica did not pass a fresh data to another one.

[DDB-906]
  • Loading branch information
Khatskevich committed Mar 21, 2024
1 parent 391ba1c commit 587ecf4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/integration/coordinator/plugins/clickhouse/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from astacus.coordinator.plugins.clickhouse.client import (
ClickHouseClient,
ClickHouseClientQueryError,
escape_sql_identifier,
escape_sql_string,
HttpClickHouseClient,
)
Expand Down Expand Up @@ -158,6 +159,7 @@ async def fixture_restored_cluster(
async with restored_cluster_manager(
restorable_cluster, ports, stop_after_step, clickhouse_restore_command, minio_bucket
) as clients:
await sync_replicated_tables(clients)
yield clients


Expand All @@ -175,6 +177,18 @@ async def fixture_function_restored_cluster(
yield clients


async def sync_replicated_tables(clients: Sequence[ClickHouseClient]) -> None:
# Get replicated tables to sync
rows = await clients[0].execute(
b"SELECT name FROM system.tables WHERE database = 'default' AND engine like 'Replicated%'"
)
for client in clients:
for row in rows:
table_name = row[0]
assert isinstance(table_name, str)
await client.execute(f"SYSTEM SYNC REPLICA default.{escape_sql_identifier(table_name.encode())} STRICT".encode())


async def setup_cluster_content(clients: Sequence[HttpClickHouseClient], use_named_collections: bool) -> None:
for client in clients:
await client.execute(b"DROP DATABASE default SYNC")
Expand Down

0 comments on commit 587ecf4

Please sign in to comment.