forked from mtusi2026/mtusi2026lab5
42 lines
1.5 KiB
Python
Executable File
42 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Fault injection around S3 effects, DB commit and broker ack."""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
from client import Client, arguments, check, run
|
|
|
|
|
|
def executable(value):
|
|
path = Path(value).resolve()
|
|
check(path.is_file() and os.access(path, os.X_OK), str(path) + ': not executable')
|
|
return path
|
|
|
|
|
|
def main():
|
|
def configure(parser):
|
|
parser.add_argument('--stop-worker-script', required=True)
|
|
parser.add_argument('--crash-worker-script', required=True)
|
|
parser.add_argument('--mode', choices=('objects', 'commit'), required=True)
|
|
|
|
args = arguments('Worker crash around durable effects', configure)
|
|
stop = executable(args.stop_worker_script)
|
|
crash = executable(args.crash_worker_script)
|
|
client = Client(args.base_url, args.ca_file)
|
|
alice, bob, _eve, chat = client.bootstrap()
|
|
subprocess.run([str(stop)], check=True)
|
|
attachment, original = client.attachment(alice, chat)
|
|
subprocess.run([str(crash), args.mode], check=True)
|
|
ready = client.wait_ready(bob, attachment)
|
|
names = sorted(item['name'] for item in ready['variants'])
|
|
check(names == ['crop', 'optimized', 'thumbnail'], 'duplicate or missing variants')
|
|
downloaded = client.call(
|
|
'GET', f'/api/v1/attachments/{attachment["id"]}/content', actor=bob
|
|
)['bytes']
|
|
check(downloaded == original, 'original changed after crash recovery')
|
|
print('PASS: worker crash mode=%s recovered one logical result' % args.mode)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run(main)
|