#!/usr/bin/env python3 """Short local fault checks; requires a running Compose stand. No load test.""" import hashlib import json import subprocess import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests')) from client import Client, Failure, check from image_probe import jpeg_size def dc(*args, ok=True): r = subprocess.run(['docker', 'compose', *args], capture_output=True, text=True, timeout=90) if ok and r.returncode: raise RuntimeError('compose action failed: ' + ' '.join(args[:2])) return r def sql(query): return dc('exec', '-T', 'postgres', 'psql', '-U', 'messenger', '-d', 'messenger', '-At', '-v', 'ON_ERROR_STOP=1', '-c', query).stdout.strip() def wait_for(predicate, message, timeout=100): end = time.monotonic()+timeout while time.monotonic()int(before) wait_for(restarted,'worker did not restart after losing DB session') att,content=c.attachment(a,chat) verify(c,a,att,content) print('PASS: lost DB session automatically restarts worker and processing resumes') finally: subprocess.run(['docker','rm','-f','lab5-retry-worker'],capture_output=True) dc('start','broker','worker',ok=False)