Try to fix PG integration tests

This commit is contained in:
Raúl Marín 2024-10-15 17:56:37 +02:00
parent fd3e6f629f
commit e95ecc07c4

View File

@ -1,5 +1,6 @@
import psycopg2
import time
import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
postgres_table_template = """
@ -245,9 +246,9 @@ class PostgresManager:
):
postgres_database = self.database_or_default(postgres_database)
self.created_materialized_postgres_db_list.add(materialized_database)
self.instance.query(f"DROP DATABASE IF EXISTS {materialized_database}")
self.instance.query(f"DROP DATABASE IF EXISTS `{materialized_database}`")
create_query = f"CREATE DATABASE {materialized_database} ENGINE = MaterializedPostgreSQL('{ip}:{port}', '{postgres_database}', '{user}', '{password}')"
create_query = f"CREATE DATABASE `{materialized_database}` ENGINE = MaterializedPostgreSQL('{ip}:{port}', '{postgres_database}', '{user}', '{password}')"
if len(settings) > 0:
create_query += " SETTINGS "
for i in range(len(settings)):
@ -259,7 +260,7 @@ class PostgresManager:
assert materialized_database in self.instance.query("SHOW DATABASES")
def drop_materialized_db(self, materialized_database="test_database"):
self.instance.query(f"DROP DATABASE IF EXISTS {materialized_database} SYNC")
self.instance.query(f"DROP DATABASE IF EXISTS `{materialized_database}` SYNC")
if materialized_database in self.created_materialized_postgres_db_list:
self.created_materialized_postgres_db_list.remove(materialized_database)
@ -342,11 +343,15 @@ def assert_nested_table_is_created(
table = schema_name + "." + table_name
print(f"Checking table {table} exists in {materialized_database}")
database_tables = instance.query(f"SHOW TABLES FROM {materialized_database}")
database_tables = instance.query(
f"SHOW TABLES FROM `{materialized_database}` WHERE name = '{table}'"
)
while table not in database_tables:
time.sleep(0.2)
database_tables = instance.query(f"SHOW TABLES FROM {materialized_database}")
database_tables = instance.query(
f"SHOW TABLES FROM `{materialized_database}` WHERE name = '{table}'"
)
assert table in database_tables
@ -372,6 +377,7 @@ def check_tables_are_synchronized(
postgres_database="postgres_database",
materialized_database="test_database",
schema_name="",
columns=["*"],
):
assert_nested_table_is_created(
instance, table_name, materialized_database, schema_name
@ -379,15 +385,15 @@ def check_tables_are_synchronized(
table_path = ""
if len(schema_name) == 0:
table_path = f"{materialized_database}.{table_name}"
table_path = f"`{materialized_database}`.`{table_name}`"
else:
table_path = f"{materialized_database}.`{schema_name}.{table_name}`"
table_path = f"`{materialized_database}`.`{schema_name}.{table_name}`"
print(f"Checking table is synchronized: {table_path}")
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 {','.join(columns)} from `{postgres_database}`.`{table_name}` order by {order_by};"
)
result = instance.query(result_query)