Skip to content
Snippets Groups Projects
Commit 1b65a39d authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

change(test_postgresql): separte write/read/del statements, and use a incremental timer for read

parent 1b717cc3
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import socket ...@@ -11,6 +11,7 @@ import socket
import subprocess import subprocess
import sys import sys
import time import time
import uuid
try: try:
import psycopg2 import psycopg2
...@@ -250,17 +251,40 @@ def check_replication(primary: dict, standby: dict) -> bool: ...@@ -250,17 +251,40 @@ def check_replication(primary: dict, standby: dict) -> bool:
error("Cannot connect to the databases") error("Cannot connect to the databases")
return False 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: try:
primary_psql = primary_client.cursor() primary_psql = primary_client.cursor()
primary_psql.execute("CREATE TABLE es_test (id serial PRIMARY KEY);") primary_psql.execute(write_query)
time.sleep(3)
standby_psql = primary_client.cursor()
standby_psql.execute("SELECT * FROM es_test;")
primary_psql.execute("DROP TABLE es_test;")
except psycopg2.Error: except psycopg2.Error:
return False 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 # close
primary_psql.close() primary_psql.close()
standby_psql.close() standby_psql.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment