"""Public persistence/failover hooks plus actual container restart evidence.""" import json import subprocess import uuid from pipeline_helpers import * def snapshots(): services=('postgres','redis','s3','broker','api1','api2','dispatcher','worker','cleanup','nginx') result={} for service in services: container=compose('ps','-q',service) info=subprocess.run(['docker','inspect',container],capture_output=True,text=True,check=True) data=json.loads(info.stdout)[0] result[service]=dict(id=data['Id'],started_at=data['State']['StartedAt']) return result def main(): client=Client();ready(client) before=snapshots() base=client.base command=['make','test-persistence','ACTION_SCRIPT=scripts/restart.sh','BASE_URL='+base] result=subprocess.run(command,cwd=ROOT,capture_output=True,text=True) check(result.returncode==0,'public persistence failed: '+result.stdout[-500:]) after=snapshots() check(all(before[s]['started_at']!=after[s]['started_at'] for s in before),'hook did not restart all required services') output={'persistence':dict(status='PASS',before=before,after=after),'failover':[]} public=subprocess.run(['make','test-failover','ACTION_SCRIPT=scripts/stop-one.sh','BASE_URL='+base],cwd=ROOT,capture_output=True,text=True) check(public.returncode==0,'public failover failed: '+public.stdout[-500:]) output['public_failover']=dict(status='PASS',output=public.stdout.strip()) try: compose('start','api1','api2');ready(client) actor,_,_,chat=client.bootstrap() item=upload(client,actor,chat);wait_state(client,actor,item) raw=(ROOT/'tests/fixtures/sample.png').read_bytes() path='/api/v1/chats/'+chat['id']+'/messages' for target in ('api-1','api-2'): compose('start','api1','api2');ready(client) seen=set() wait_for(lambda: (seen.add(client.call('GET','/health/ready')['headers']['X-Instance-Id']) or len(seen)==2),'two replicas not visible') process=subprocess.Popen([str(ROOT/'scripts/stop-one.sh')],cwd=ROOT, env=dict(os.environ,TARGET_INSTANCE_ID=target),stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) began=time.monotonic();deadline=began+8;first=None;confirmed=set();failures=0 key=uuid.uuid4().hex while time.monotonic()