forked from mtusi2026/mtusi2026lab5
48 lines
1.7 KiB
Python
Executable File
48 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""A persistent broker volume keeps a confirmed job across broker restart."""
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import time
|
|
|
|
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('--restart-broker-script', required=True)
|
|
parser.add_argument('--start-worker-script', required=True)
|
|
|
|
args = arguments('RabbitMQ persistent delivery after restart', configure)
|
|
stop_worker = executable(args.stop_worker_script)
|
|
restart_broker = executable(args.restart_broker_script)
|
|
start_worker = executable(args.start_worker_script)
|
|
client = Client(args.base_url, args.ca_file)
|
|
alice, bob, _eve, chat = client.bootstrap()
|
|
subprocess.run([str(stop_worker)], check=True)
|
|
attachment, original = client.attachment(alice, chat)
|
|
time.sleep(2)
|
|
queued = client.call(
|
|
'GET', f'/api/v1/attachments/{attachment["id"]}', actor=bob, schema='Attachment'
|
|
)['json']
|
|
check(queued['status'] == 'queued', 'worker processed job while expected stopped')
|
|
subprocess.run([str(restart_broker)], check=True)
|
|
subprocess.run([str(start_worker)], check=True)
|
|
client.wait_ready(bob, attachment)
|
|
downloaded = client.call(
|
|
'GET', f'/api/v1/attachments/{attachment["id"]}/content', actor=bob
|
|
)['bytes']
|
|
check(downloaded == original, 'job/original lost across broker restart')
|
|
print('PASS: confirmed durable message survived broker restart with its volume')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run(main)
|