Add a test

This commit is contained in:
kssenii 2023-12-06 20:23:09 +01:00
parent 9cf87f4261
commit 6321576ff8
2 changed files with 36 additions and 7 deletions

View File

@ -189,11 +189,11 @@ class PostgresManager:
database_name = self.database_or_default(database_name)
self.drop_postgres_db(database_name)
self.created_postgres_db_list.add(database_name)
self.cursor.execute(f"CREATE DATABASE {database_name}")
self.cursor.execute(f"CREATE DATABASE \"{database_name}\"")
def drop_postgres_db(self, database_name=""):
database_name = self.database_or_default(database_name)
self.cursor.execute(f"DROP DATABASE IF EXISTS {database_name} WITH (FORCE)")
self.cursor.execute(f"DROP DATABASE IF EXISTS \"{database_name}\" WITH (FORCE)")
if database_name in self.created_postgres_db_list:
self.created_postgres_db_list.remove(database_name)
@ -212,19 +212,19 @@ class PostgresManager:
if len(schema_name) == 0:
self.instance.query(
f"""
CREATE DATABASE {database_name}
CREATE DATABASE \"{database_name}\"
ENGINE = PostgreSQL('{self.ip}:{self.port}', '{postgres_database}', 'postgres', 'mysecretpassword')"""
)
else:
self.instance.query(
f"""
CREATE DATABASE {database_name}
CREATE DATABASE \"{database_name}\"
ENGINE = PostgreSQL('{self.ip}:{self.port}', '{postgres_database}', 'postgres', 'mysecretpassword', '{schema_name}')"""
)
def drop_clickhouse_postgres_db(self, database_name=""):
database_name = self.database_or_default(database_name)
self.instance.query(f"DROP DATABASE IF EXISTS {database_name}")
self.instance.query(f"DROP DATABASE IF EXISTS \"{database_name}\"")
if database_name in self.created_ch_postgres_db_list:
self.created_ch_postgres_db_list.remove(database_name)
@ -362,7 +362,7 @@ def check_tables_are_synchronized(
result_query = f"select * from {table_path} order by {order_by};"
expected = instance.query(
f"select * from {postgres_database}.{table_name} order by {order_by};"
f"select * from `{postgres_database}`.`{table_name}` order by {order_by};"
)
result = instance.query(result_query)
@ -376,7 +376,7 @@ def check_tables_are_synchronized(
if result != expected:
count = int(instance.query(f"select count() from {table_path}"))
expected_count = int(
instance.query(f"select count() from {postgres_database}.{table_name}")
instance.query(f"select count() from `{postgres_database}`.`{table_name}`")
)
print(f"Having {count}, expected {expected_count}")
assert result == expected

View File

@ -58,6 +58,7 @@ instance2 = cluster.add_instance(
pg_manager = PostgresManager()
pg_manager2 = PostgresManager()
pg_manager_instance2 = PostgresManager()
pg_manager3 = PostgresManager()
@pytest.fixture(scope="module")
@ -80,6 +81,12 @@ def started_cluster():
pg_manager2.init(
instance2, cluster.postgres_ip, cluster.postgres_port, "postgres_database2"
)
pg_manager3.init(
instance,
cluster.postgres_ip,
cluster.postgres_port,
default_database="postgres-postgres",
)
yield cluster
@ -810,6 +817,28 @@ def test_replica_consumer(started_cluster):
pg_manager_instance2.clear()
def test_symbols_in_publication_name(started_cluster):
table = "test_symbols_in_publication_name"
pg_manager3.create_postgres_table(table)
instance.query(
f"INSERT INTO `{pg_manager3.get_default_database()}`.`{table}` SELECT number, number from numbers(0, 50)"
)
pg_manager3.create_materialized_db(
ip=started_cluster.postgres_ip,
port=started_cluster.postgres_port,
settings=[
f"materialized_postgresql_tables_list = '{table}'",
"materialized_postgresql_backoff_min_ms = 100",
"materialized_postgresql_backoff_max_ms = 100",
],
)
check_tables_are_synchronized(
instance, table, postgres_database=pg_manager3.get_default_database()
)
if __name__ == "__main__":
cluster.start()
input("Cluster created, press any key to destroy...")