forked from mtusi2026/mtusi2026lab5
Лабораторная 5
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
python scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
|
||||
python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
|
||||
docker compose config --quiet
|
||||
PASS
|
||||
|
||||
docker compose up -d --build
|
||||
PASS; postgres, s3, broker, api1, api2, load-balancer and worker started.
|
||||
|
||||
docker exec mtusi-lab5-api1-1 python tests/smoke.py --base-url http://127.0.0.1:8080
|
||||
PASS: lab5 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,12 @@
|
||||
Focused code execution using Pillow 12, executing the actual worker image functions:
|
||||
input: RGBA PNG, 320x200
|
||||
thumbnail: JPEG 256x160
|
||||
crop: JPEG 128x128
|
||||
optimized: WebP 320x200 (small source was not upscaled)
|
||||
EXIF: absent from WebP result
|
||||
|
||||
Focused execution output: PASS.
|
||||
|
||||
Unit tests:
|
||||
python -m unittest discover -s student-tests
|
||||
Result: PASS (23 tests).
|
||||
@@ -0,0 +1,53 @@
|
||||
Live runtime verification
|
||||
=========================
|
||||
|
||||
Environment:
|
||||
Windows; Docker Compose stack for this repository.
|
||||
HTTP_PORT=18080 because port 8080 was occupied by another lab; that stack was not stopped.
|
||||
Tests use synthetic users, messages, and images only. No volumes were removed.
|
||||
|
||||
Public API smoke through nginx:
|
||||
python tests/smoke.py --base-url http://127.0.0.1:18080
|
||||
PASS: lab5 public API scenario.
|
||||
|
||||
Accepted upload while worker was stopped, then full stack restart:
|
||||
BASE_URL=http://127.0.0.1:18080 HTTP_PORT=18080 python scripts/worker_outage_live.py
|
||||
PASS:
|
||||
accepted_status=queued
|
||||
final_status=ready
|
||||
durable job/outbox state=ready|1|1|1
|
||||
original_unchanged=true
|
||||
confirmed_message_preserved=true
|
||||
The test stops only this lab's worker, uploads an attachment and confirms the API
|
||||
remains available, then runs scripts/restart.cmd (compose down/up without -v).
|
||||
It verifies the same attachment and confirmed message after recovery.
|
||||
|
||||
Crash immediately before and after original S3 put:
|
||||
BASE_URL=http://127.0.0.1:18080 HTTP_PORT=18080 python scripts/fault_injection_live.py
|
||||
PASS:
|
||||
before_original_put: ready|2|1|retry; original_unchanged=true
|
||||
after_original_put: ready|2|1|retry; original_unchanged=true
|
||||
|
||||
Failed event, explicit replay, and expired lease:
|
||||
BASE_URL=http://127.0.0.1:18080 HTTP_PORT=18080 python scripts/replay_live.py
|
||||
PASS:
|
||||
failed_event_published=true
|
||||
replay_state=ready|1|1|1
|
||||
lease_recovery_state=ready|3|1|1
|
||||
operator=live-lab5-test
|
||||
original_unchanged=true
|
||||
|
||||
API replica failover:
|
||||
tests/resilience.py --mode failover --action-script scripts/stop-one.cmd
|
||||
PASS: two API instances observed before failure; 101 successful writes,
|
||||
1 transition failure, first recovery in 0.687 seconds. Confirmed messages and
|
||||
attachment remained available; both API replicas were restored after the test.
|
||||
This is a short failover test, not a load benchmark or p95/p99 measurement.
|
||||
|
||||
Staging cleanup:
|
||||
Synthetic attachment cleanup scenario: deletion marker recorded, staging object
|
||||
absent, final original still present.
|
||||
|
||||
All live test scripts use unique synthetic records. Runtime failpoint injection is
|
||||
disabled by default and was cleared after testing. No user data or secrets are in
|
||||
this evidence.
|
||||
@@ -0,0 +1,18 @@
|
||||
Migration: migrations/001_lab5.sql
|
||||
Outbox table verified in PostgreSQL.
|
||||
|
||||
Observed after public smoke:
|
||||
event_type=attachment.process
|
||||
publish_attempt=1
|
||||
published_at=2026-11-24 13:36:03.511287+00
|
||||
job status=ready
|
||||
|
||||
Publisher behavior:
|
||||
- API inserts staging, attachment, job and outbox in one transaction.
|
||||
- Worker publisher polls unpublished rows.
|
||||
- Publish is accepted only through RabbitMQ publisher confirm.
|
||||
- published_at is set only after confirm.
|
||||
|
||||
Live recovery of a queued attachment with the worker stopped and the full Compose
|
||||
stack restarted is recorded in evidence/live-runtime.txt. The job completed from
|
||||
the durable outbox without a new client upload.
|
||||
@@ -0,0 +1,30 @@
|
||||
Command:
|
||||
python -m unittest discover -s student-tests
|
||||
|
||||
Result:
|
||||
PASS (23 tests)
|
||||
|
||||
Fault-injection coverage:
|
||||
- Triggered the production child-exit failpoint before and after the original S3 write
|
||||
(the test substitutes os._exit with a sentinel exception to inspect resulting state).
|
||||
- Verified retry is scheduled with the next attempt number.
|
||||
- Verified stale first-attempt redelivery does not create side effects.
|
||||
- Verified retry uses deterministic object keys and reaches ready.
|
||||
- Verified duplicate delivery after ready does not overwrite objects.
|
||||
- Verified a v1 event cannot process or overwrite a v2 job; the v2 event completes.
|
||||
- Verified pipeline versions use distinct, fixed encoding qualities.
|
||||
- Verified staging cleanup ignores processing jobs and is idempotent for ready jobs.
|
||||
- Verified publisher marks outbox published only after confirm; publish failure remains retryable.
|
||||
- Verified expired leases enqueue the next attempt.
|
||||
- Verified replay is limited to failed attachments and writes operator audit/outbox intent.
|
||||
- Verified permanent failures and exhausted retries are registered and routed to the failed event.
|
||||
|
||||
Scope:
|
||||
The tests exercise production worker functions with in-memory PostgreSQL/S3 adapters.
|
||||
Live Docker/PostgreSQL/S3/RabbitMQ crash scenarios were also verified; see
|
||||
evidence/live-runtime.txt for the exact scenarios and observed states.
|
||||
|
||||
Invariants:
|
||||
- HTTP-accepted jobs have staging, job, and outbox intent committed atomically (see evidence/outbox.txt).
|
||||
- The worker acknowledges only after a ready/failed state or a retry outbox event is committed.
|
||||
- Delivery is at-least-once, not exactly-once; deterministic keys and version/attempt fences make repeats safe.
|
||||
Reference in New Issue
Block a user