Files
mtusi2026lab6/tests/attachment_load.py
T

51 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Create queued attachment jobs without printing credentials or message bodies."""
import json
from pathlib import Path
import time
from client import Client, arguments, check, run
def main():
def configure(parser):
parser.add_argument('--count', type=int, default=10)
parser.add_argument('--interval', type=float, default=0.1)
parser.add_argument('--output', default=None)
args = arguments('Synthetic attachment load for worker telemetry', configure)
check(1 <= args.count <= 1000, 'count must be 1..1000')
check(0 <= args.interval <= 60, 'interval must be 0..60 seconds')
client = Client(args.base_url, args.ca_file)
alice, _bob, _eve, chat = client.bootstrap()
started = time.monotonic()
accepted = 0
errors = 0
for _ in range(args.count):
try:
client.attachment(alice, chat)
accepted += 1
except Exception:
errors += 1
if args.interval:
time.sleep(args.interval)
report = {
'workload': 'synthetic PNG attachment uploads',
'requested': args.count,
'accepted': accepted,
'errors': errors,
'elapsed_seconds': round(time.monotonic() - started, 3),
'contains_credentials': False,
}
text = json.dumps(report, ensure_ascii=False, indent=2)
if args.output:
destination = Path(args.output)
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_text(text + '\n', encoding='utf-8')
print(text)
check(accepted > 0, 'no attachment jobs were accepted')
if __name__ == '__main__':
run(main)