From 1b65a39d3648c9ceb4a74e92cb7704ef9e66e6b3 Mon Sep 17 00:00:00 2001 From: Nicolas KAROLAK <nicolas@karolak.fr> Date: Mon, 3 Sep 2018 10:55:49 +0200 Subject: [PATCH] change(test_postgresql): separte write/read/del statements, and use a incremental timer for read --- tests/test_postgresql.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index c1938f3c..d5e84740 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() -- GitLab