mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-28 03:06:29 +00:00
Validates pgcat is closed after shutdown python tests (#116)
* Validates pgcat is closed after shutdown python tests * Fix pgrep logic * Moves sigterm step to after cleanup to decouple * Replace subprocess with os.system for running pgcat
This commit is contained in:
@@ -3,8 +3,6 @@ import psycopg2
|
|||||||
import psutil
|
import psutil
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
|
||||||
from threading import Thread
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
SHUTDOWN_TIMEOUT = 5
|
SHUTDOWN_TIMEOUT = 5
|
||||||
@@ -15,14 +13,18 @@ PGCAT_PORT = "6432"
|
|||||||
|
|
||||||
def pgcat_start():
|
def pgcat_start():
|
||||||
pg_cat_send_signal(signal.SIGTERM)
|
pg_cat_send_signal(signal.SIGTERM)
|
||||||
pgcat_start_command = "./target/debug/pgcat .circleci/pgcat.toml"
|
os.system("./target/debug/pgcat .circleci/pgcat.toml &")
|
||||||
subprocess.Popen(pgcat_start_command.split())
|
|
||||||
|
|
||||||
|
|
||||||
def pg_cat_send_signal(signal: signal.Signals):
|
def pg_cat_send_signal(signal: signal.Signals):
|
||||||
for proc in psutil.process_iter(["pid", "name"]):
|
for proc in psutil.process_iter(["pid", "name"]):
|
||||||
if "pgcat" == proc.name():
|
if "pgcat" == proc.name():
|
||||||
os.kill(proc.pid, signal)
|
os.kill(proc.pid, signal)
|
||||||
|
if signal == signal.SIGTERM:
|
||||||
|
# Returns 0 if pgcat process exists
|
||||||
|
time.sleep(2)
|
||||||
|
if not os.system('pgrep pgcat'):
|
||||||
|
raise Exception("pgcat not closed after SIGTERM")
|
||||||
|
|
||||||
|
|
||||||
def connect_normal_db(
|
def connect_normal_db(
|
||||||
@@ -67,8 +69,7 @@ def test_shutdown_logic():
|
|||||||
|
|
||||||
##### NO ACTIVE QUERIES SIGINT HANDLING #####
|
##### NO ACTIVE QUERIES SIGINT HANDLING #####
|
||||||
# Start pgcat
|
# Start pgcat
|
||||||
server = Thread(target=pgcat_start)
|
pgcat_start()
|
||||||
server.start()
|
|
||||||
|
|
||||||
# Wait for server to fully start up
|
# Wait for server to fully start up
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@@ -92,12 +93,15 @@ def test_shutdown_logic():
|
|||||||
else:
|
else:
|
||||||
# Fail if query execution succeeded
|
# Fail if query execution succeeded
|
||||||
raise Exception("Server not closed after sigint")
|
raise Exception("Server not closed after sigint")
|
||||||
|
|
||||||
cleanup_conn(conn, cur)
|
cleanup_conn(conn, cur)
|
||||||
|
pg_cat_send_signal(signal.SIGTERM)
|
||||||
|
|
||||||
|
##### END #####
|
||||||
|
|
||||||
##### HANDLE TRANSACTION WITH SIGINT #####
|
##### HANDLE TRANSACTION WITH SIGINT #####
|
||||||
# Start pgcat
|
# Start pgcat
|
||||||
server = Thread(target=pgcat_start)
|
pgcat_start()
|
||||||
server.start()
|
|
||||||
|
|
||||||
# Wait for server to fully start up
|
# Wait for server to fully start up
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@@ -120,11 +124,13 @@ def test_shutdown_logic():
|
|||||||
raise Exception("Server closed while in transaction", e.pgerror)
|
raise Exception("Server closed while in transaction", e.pgerror)
|
||||||
|
|
||||||
cleanup_conn(conn, cur)
|
cleanup_conn(conn, cur)
|
||||||
|
pg_cat_send_signal(signal.SIGTERM)
|
||||||
|
|
||||||
|
##### END #####
|
||||||
|
|
||||||
##### HANDLE SHUTDOWN TIMEOUT WITH SIGINT #####
|
##### HANDLE SHUTDOWN TIMEOUT WITH SIGINT #####
|
||||||
# Start pgcat
|
# Start pgcat
|
||||||
server = Thread(target=pgcat_start)
|
pgcat_start()
|
||||||
server.start()
|
|
||||||
|
|
||||||
# Wait for server to fully start up
|
# Wait for server to fully start up
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -151,6 +157,9 @@ def test_shutdown_logic():
|
|||||||
raise Exception("Server not closed after sigint and expected timeout")
|
raise Exception("Server not closed after sigint and expected timeout")
|
||||||
|
|
||||||
cleanup_conn(conn, cur)
|
cleanup_conn(conn, cur)
|
||||||
|
pg_cat_send_signal(signal.SIGTERM)
|
||||||
|
|
||||||
|
##### END #####
|
||||||
|
|
||||||
|
|
||||||
test_normal_db_access()
|
test_normal_db_access()
|
||||||
|
|||||||
Reference in New Issue
Block a user