test(lab5): add chaos scripts, fault generation tool and evidence logs
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent / 'tests'))
|
||||
from client import Client, arguments
|
||||
|
||||
def main():
|
||||
args = arguments('Генерация упавшей задачи для failed_jobs')
|
||||
c = Client(args.base_url, args.ca_file)
|
||||
|
||||
print("Создаем тестовых пользователей и чат...")
|
||||
alice, bob, eve, chat = c.bootstrap()
|
||||
|
||||
print("Генерируем битый PNG (берем начало от настоящей картинки)...")
|
||||
sample = Path("tests/fixtures/sample.png").read_bytes()
|
||||
broken_png = sample[:100]
|
||||
|
||||
print("Загружаем битый файл через API...")
|
||||
# Добавили schema='Attachment', чтобы клиент распарсил JSON
|
||||
r = c.call(
|
||||
'POST',
|
||||
f"/api/v1/chats/{chat['id']}/attachments?filename=broken.png",
|
||||
202,
|
||||
actor=alice,
|
||||
raw=broken_png,
|
||||
headers={'Content-Type': 'image/png'},
|
||||
schema='Attachment'
|
||||
)
|
||||
|
||||
att_id = r['json']['id']
|
||||
print(f"Файл принят! ID: {att_id}, статус: {r['json']['status']}")
|
||||
print("Ждем 5 секунд, пока Worker попытается его обработать и упадет...")
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
# Проверяем статус
|
||||
att = c.call('GET', f'/api/v1/attachments/{att_id}', actor=alice, schema='Attachment')['json']
|
||||
print(f"Итоговый статус: {att['status']}, ошибка: {att['error_code']}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user