diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index c1938f3c9cb35cb51eaa8a486f5e0ff280d7d3ce..d5e84740e981f2b8b6273d58a464cfd4bd7e0a0b 100755 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -11,6 +11,7 @@ import socket import subprocess import sys import time +import uuid try: import psycopg2 @@ -250,17 +251,40 @@ def check_replication(primary: dict, standby: dict) -> bool: error("Cannot connect to the databases") return False - # queries + # random id + rand = uuid.uuid4().hex + write_query = "CREATE TABLE es_test_{} (id serial PRIMARY KEY);".format(rand) + read_query = "SELECT * FROM es_test_{};".format(rand) + del_query = "DROP TABLE es_test_{};".format(rand) + + # write try: primary_psql = primary_client.cursor() - primary_psql.execute("CREATE TABLE es_test (id serial PRIMARY KEY);") - time.sleep(3) - standby_psql = primary_client.cursor() - standby_psql.execute("SELECT * FROM es_test;") - primary_psql.execute("DROP TABLE es_test;") + primary_psql.execute(write_query) except psycopg2.Error: return False + # read + max_time = 6.0 + timer = 0.0 + while timer < max_time: + time.sleep(timer) + timer += 0.2 + try: + standby_psql = primary_client.cursor() + standby_psql.execute(read_query) + break + except psycopg2.Error: + pass + else: + return False + + # delete + try: + primary_psql.execute(del_query) + except psycopg2.Error: + pass + # close primary_psql.close() standby_psql.close()