Собрать стенд лабораторной 5: очередь, worker и идемпотентность pipeline.

This commit is contained in:
Wladislava1
2026-11-12 13:05:02 +03:00
parent 276dbdad8a
commit a1b972f7d9
39 changed files with 5492 additions and 34 deletions
+20
View File
@@ -0,0 +1,20 @@
{
"file": "JPEG 200x100, EXIF Orientation 6, red pixels",
"in_process_render": {
"where": "docker exec mtusi-lab5-worker-1 python, function images.render",
"original_unchanged": true,
"thumbnail": [100, 200],
"crop": [128, 128],
"optimized": [100, 200]
},
"http_upload": {
"command": "POST /api/v1/chats/{id}/attachments?filename=orient6.jpg",
"upload_status": "queued",
"final_status": "ready",
"variants": {
"thumbnail": [100, 200],
"crop": [128, 128],
"optimized": [100, 200]
}
}
}
+24
View File
@@ -0,0 +1,24 @@
Команда (через WSL):
python3 -X utf8 tests/resilience.py --mode failover --action-script scripts/stop-one.sh --base-url http://127.0.0.1:8080
Прогон 1, код выхода 0:
{"observed_instances_before": 2, "successful_writes": 97, "failed_attempts": 1, "first_recovery_seconds": 1.469}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
Остановлен mtusi-lab5-api-2, exit 143, FinishedAt 2026-11-12T09:00:09.569371803Z.
mtusi-lab5-api-1 остался running.
Между прогонами реплика поднята командой:
docker compose --env-file .env up -d --no-deps --scale api=2 api
Прогон 2, код выхода 0:
{"observed_instances_before": 2, "successful_writes": 98, "failed_attempts": 1, "first_recovery_seconds": 0.975}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
Снова остановлен mtusi-lab5-api-2, exit 143. api-1 остался running.
Публичный тест оба раза выбрал ту реплику, которая последней ответила. Это был api-2.
Отдельная проверка второй реплики, тот же scripts/stop-one.sh:
TARGET_INSTANCE_ID=2e03f20dd3b5
Остановлен mtusi-lab5-api-1, hostname 2e03f20dd3b5, exit 143.
mtusi-lab5-api-2 остался running.
После проверки реплика снова запущена. Дата: 12 ноября 2026.
+23
View File
@@ -0,0 +1,23 @@
{
"command": "python -X utf8 student-tests/run_negative.py http://127.0.0.1:8080",
"result": "PASS negative",
"results": [
{"name": "chat_uuid_case", "status": 200},
{"name": "blank_text", "status": 400},
{"name": "bad_json", "status": 400},
{"name": "short_password", "status": 400},
{"name": "omitted_equals_empty", "status": 201},
{"name": "same_key_other_body", "status": 409},
{"name": "no_second_row", "status": 200},
{"name": "same_key_other_chat", "status": 201},
{"name": "foreign_chat", "status": 404},
{"name": "bad_cursor", "status": 400},
{"name": "slash_name", "status": 400},
{"name": "huge_pixels", "status": 413},
{"name": "bad_png", "status": 415},
{"name": "type_mismatch", "status": 415},
{"name": "oversize", "status": 413},
{"name": "unknown_attachment", "status": 404},
{"name": "no_token", "status": 401}
]
}
+20
View File
@@ -0,0 +1,20 @@
Команда (через WSL, потому что Windows не запускает .sh):
python3 -X utf8 tests/resilience.py --mode persistence --action-script scripts/restart.sh --base-url http://127.0.0.1:8080
Вывод:
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
Код выхода: 0. Дата: 12 ноября 2026.
StartedAt после hook:
postgres 2026-11-12T08:58:51.311769003Z
redis 2026-11-12T08:58:50.947096648Z
minio 2026-11-12T08:58:51.30945974Z
rabbitmq 2026-11-12T08:59:03.356512147Z
api-1 2026-11-12T08:59:15.032550589Z
api-2 2026-11-12T08:59:14.961115981Z
lb 2026-11-12T08:56:49.466505107Z (не перезапускался)
worker 2026-11-12T08:56:32.031493932Z (скрипт его не трогает)
Hook перезапускает postgres, redis, minio, rabbitmq и api. Volume не удалялись.
+318
View File
@@ -0,0 +1,318 @@
{
"results": [
{
"name": "durability",
"ok": true,
"seconds": 122.813,
"detail": {
"upload_status": "queued",
"content_while_queued": 409,
"text_status": 201,
"text_id": "0cb05d10-70d9-46a2-9fad-3272a92af1b3",
"linked_id": "5ffaee48-8e7c-4742-a5f1-b2991fed1a4b",
"queue_before_api_restart": 1,
"queue_after_api_restart": 1,
"queue_after_rabbit_restart": 1,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "outbox_gap",
"ok": true,
"seconds": 26.781,
"detail": {
"unpublished_before_worker": 1,
"queue_depth": 0,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "duplicate",
"ok": true,
"seconds": 19.203,
"detail": {
"republish": true,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "reorder",
"ok": true,
"seconds": 19.688,
"detail": {
"attempt": 1,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "stale_version",
"ok": true,
"seconds": 26.906,
"detail": {
"bump": {
"job_id": "a7af6898-08db-4a00-aff6-a2b654e3e0da",
"pipeline_version": 2
},
"old_job_status": "superseded",
"old_error_code": "superseded",
"attachment_error_code": null,
"picture": {
"pipeline_version": 2,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
},
"thumbnail_unchanged": true
}
},
{
"name": "crash_before_effect",
"ok": true,
"seconds": 19.281,
"detail": {
"restart_count_before": 0,
"restart_count_after": 1,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "crash_after_objects",
"ok": true,
"seconds": 14.968,
"detail": {
"started_at": "2026-11-12T09:24:05.644199607Z",
"restarted_at": "2026-11-12T09:24:09.042866995Z",
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "crash_after_commit",
"ok": true,
"seconds": 11.563,
"detail": {
"started_at": "2026-11-12T09:24:21.448659497Z",
"restarted_at": "2026-11-12T09:24:24.489665631Z",
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "transient_once",
"ok": true,
"seconds": 13.187,
"detail": {
"attempt": 2,
"events": [
"leased",
"retry",
"leased",
"ready"
],
"variant_rows": 4,
"status": "ready"
}
},
{
"name": "permanent_replay",
"ok": true,
"seconds": 28.407,
"detail": {
"corrupt_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75",
"failed_code": "invalid_image",
"attempt_at_fail": 1,
"restored_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75",
"replay": {
"result": "queued"
},
"second_replay": {
"result": "already_ready"
},
"variant_rows": 4,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "lease",
"ok": true,
"seconds": 41.14,
"detail": {
"seconds_until_ready": 17.078,
"events": [
"lease_expired",
"leased",
"ready"
],
"attempt": 1,
"picture": {
"pipeline_version": 1,
"variant_rows": 4,
"thumbnail": [
256,
160
],
"crop": [
128,
128
],
"optimized": [
320,
200
],
"original_sha256": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75"
}
}
},
{
"name": "ready_503",
"ok": true,
"seconds": 13.625,
"detail": {
"lb_status": 503,
"lb_body": "<html><body><h1>503 Service Unavailable</h1>\nNo server is available to handle this request.\n</body></html>\n",
"api_status": 503,
"api_message": "Сервис временно недоступен",
"forbidden": [],
"recovered": 200,
"recovery_seconds": 0.063
}
}
]
}