1
0
mirror of https://github.com/tensorchord/pgvecto.rs.git synced 2025-07-30 19:23:05 +03:00
Files
pgvecto.rs/tests/crash/kill.py
cutecutecat 98622ed077 chore: add crash test (#242)
* chore: add crash test

Signed-off-by: cutecutecat <junyuchen@tensorchord.ai>

* fix

Signed-off-by: cutecutecat <junyuchen@tensorchord.ai>

---------

Signed-off-by: cutecutecat <junyuchen@tensorchord.ai>
2024-01-09 08:13:13 +00:00

57 lines
1.8 KiB
Python

import logging
import time
import psutil
TIMEOUT = 30
FILTERS = ["postgres", "vectors"]
logging.getLogger().setLevel(logging.INFO)
def process_filter(p: psutil.Process) -> bool:
cmdline = "".join(p.cmdline())
for case in FILTERS:
if case not in cmdline:
return False
return True
if __name__ == "__main__":
# Send kill signal to vectors process
endpoint = time.monotonic() + TIMEOUT
last_pids = set()
while True:
if time.monotonic() > endpoint:
raise TimeoutError(f"Background worker not found in {TIMEOUT}s")
procs = [p for p in psutil.process_iter() if process_filter(p)]
last_pids = set(p.pid for p in procs)
if len(procs) > 0:
logging.info(f"Kill signal sent to {last_pids}")
for p in procs:
p.kill()
break
time.sleep(1)
# Wait until process is not exist or recreated
endpoint = time.monotonic() + TIMEOUT
while True:
if time.monotonic() > endpoint:
raise TimeoutError(f"Background worker not killed in {TIMEOUT}s")
procs = [p for p in psutil.process_iter() if process_filter(p)]
pids = set(p.pid for p in procs)
if len(pids & last_pids) == 0:
logging.info(f"Background worker killed {last_pids}, now {pids}")
break
# Wait until process is recreated
endpoint = time.monotonic() + TIMEOUT
while True:
if time.monotonic() > endpoint:
raise TimeoutError(f"Background worker not recreated in {TIMEOUT}s")
procs = [p for p in psutil.process_iter() if process_filter(p)]
pids = set(p.pid for p in procs)
if len(procs) == 1:
logging.info(f"Background worker recreated {pids}")
break
time.sleep(1)