Лабораторная работа 6
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# 2026-11-02T13:36:48Z | offline contract
|
||||
$ python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
# 2026-11-02T13:36:48Z | full OpenAPI validation
|
||||
$ python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
@@ -0,0 +1,17 @@
|
||||
# 2026-11-02T13:37:02Z | DB<->S3 consistency, aborted upload, injected faults (api-11 s3_error_on_put, api-12 db_error_after_s3_put, api-13 crash_after_s3_put)
|
||||
$ BASE_URL=... FAULT_*_URL=... python -m unittest discover -s student-tests -p test_attachment_consistency.py -v
|
||||
test_crash_between_put_and_commit_dry_run_then_apply_then_noop (test_attachment_consistency.AttachmentConsistencyTests.test_crash_between_put_and_commit_dry_run_then_apply_then_noop) ... ok
|
||||
test_fresh_pending_is_kept (test_attachment_consistency.AttachmentConsistencyTests.test_fresh_pending_is_kept) ... ok
|
||||
test_missing_object_is_reported_not_deleted (test_attachment_consistency.AttachmentConsistencyTests.test_missing_object_is_reported_not_deleted) ... ok
|
||||
test_orphan_object_deleted_only_after_grace (test_attachment_consistency.AttachmentConsistencyTests.test_orphan_object_deleted_only_after_grace) ... ok
|
||||
test_pending_cannot_be_attached (test_attachment_consistency.AttachmentConsistencyTests.test_pending_cannot_be_attached) ... ok
|
||||
test_ready_and_referenced_are_never_collected (test_attachment_consistency.AttachmentConsistencyTests.test_ready_and_referenced_are_never_collected) ... ok
|
||||
test_aborted_upload_leaves_no_row_and_no_object (test_attachment_consistency.UploadFailureTests.test_aborted_upload_leaves_no_row_and_no_object) ... ok
|
||||
test_db_failure_after_put_returns_503_and_deletes_object (test_attachment_consistency.UploadFailureTests.test_db_failure_after_put_returns_503_and_deletes_object) ... ok
|
||||
test_process_crash_after_put_is_collected_by_gc (test_attachment_consistency.UploadFailureTests.test_process_crash_after_put_is_collected_by_gc) ... ok
|
||||
test_s3_put_failure_returns_503_and_compensates (test_attachment_consistency.UploadFailureTests.test_s3_put_failure_returns_503_and_compensates) ... ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 10 tests in 4.391s
|
||||
|
||||
OK
|
||||
@@ -0,0 +1,12 @@
|
||||
# 2026-11-02T13:28:02Z failover run 1: python3 tests/resilience.py --mode failover --action-script <stop-one hook>
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 138, "failed_attempts": 0, "first_recovery_seconds": 4.468}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
2026-11-02T13:27:47Z stop-one api-1 pid 7684
|
||||
restored; next run
|
||||
# 2026-11-02T13:28:23Z failover run 2: python3 tests/resilience.py --mode failover --action-script <stop-one hook>
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 139, "failed_attempts": 0, "first_recovery_seconds": 4.475}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
2026-11-02T13:28:08Z stop-one api-1 pid 7937
|
||||
restored; next run
|
||||
@@ -0,0 +1,268 @@
|
||||
{
|
||||
"scenario": "stop each API replica in turn under load, restore before the next",
|
||||
"load": {
|
||||
"writers": 4,
|
||||
"readers": 2,
|
||||
"client_timeout_s": 2.0,
|
||||
"write_retry": "same Idempotency-Key and body until 201"
|
||||
},
|
||||
"replicas": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"rounds": [
|
||||
{
|
||||
"target_instance": "api-1",
|
||||
"mode": "stop",
|
||||
"lb_up_before": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"stop_hook_seconds": 5.0,
|
||||
"lb_detect_down_seconds": 1.3,
|
||||
"target_last_served_after_stop_seconds": 1.31,
|
||||
"target_served_after_hook_returned": false,
|
||||
"errors_during_outage": 0,
|
||||
"error_kinds": [],
|
||||
"error_window_seconds": 0.0,
|
||||
"restore_hook_seconds": 1.86,
|
||||
"lb_back_up_seconds": 2.91,
|
||||
"target_back_in_rotation_seconds": 2.87,
|
||||
"windows": {
|
||||
"before": {
|
||||
"from_s": 0,
|
||||
"to_s": 5.02,
|
||||
"requests": 1597,
|
||||
"ok": 1597,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 318.1,
|
||||
"write_ok_rps": 187.8,
|
||||
"latency_ms_ok": {
|
||||
"p50": 16.7,
|
||||
"p95": 38.6,
|
||||
"p99": 50.6
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
},
|
||||
"outage_first_10s": {
|
||||
"from_s": 5.02,
|
||||
"to_s": 15.02,
|
||||
"requests": 2392,
|
||||
"ok": 2392,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 239.2,
|
||||
"write_ok_rps": 140.9,
|
||||
"latency_ms_ok": {
|
||||
"p50": 24.4,
|
||||
"p95": 39.5,
|
||||
"p99": 48.8
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
},
|
||||
"outage_rest": {
|
||||
"from_s": 15.02,
|
||||
"to_s": 20.02,
|
||||
"requests": 1057,
|
||||
"ok": 1057,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 211.4,
|
||||
"write_ok_rps": 124.2,
|
||||
"latency_ms_ok": {
|
||||
"p50": 27.6,
|
||||
"p95": 44.5,
|
||||
"p99": 54.8
|
||||
},
|
||||
"instances": [
|
||||
"api-2"
|
||||
]
|
||||
},
|
||||
"after_restore": {
|
||||
"from_s": 20.02,
|
||||
"to_s": 26.15,
|
||||
"requests": 1671,
|
||||
"ok": 1671,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 272.8,
|
||||
"write_ok_rps": 160.7,
|
||||
"latency_ms_ok": {
|
||||
"p50": 21.2,
|
||||
"p95": 39.0,
|
||||
"p99": 49.4
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"lb_timeline": [
|
||||
[
|
||||
0.02,
|
||||
[
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
],
|
||||
[
|
||||
6.32,
|
||||
[
|
||||
"api-2"
|
||||
]
|
||||
],
|
||||
[
|
||||
22.93,
|
||||
[
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
]
|
||||
],
|
||||
"data": {
|
||||
"confirmed_writes": 3957,
|
||||
"stored_messages": 3957,
|
||||
"missing_or_altered": 0,
|
||||
"duplicate_ids": 0,
|
||||
"duplicate_texts": 0,
|
||||
"same_key_retries": 0,
|
||||
"ok": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"target_instance": "api-2",
|
||||
"mode": "stop",
|
||||
"lb_up_before": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"stop_hook_seconds": 5.23,
|
||||
"lb_detect_down_seconds": 1.53,
|
||||
"target_last_served_after_stop_seconds": 1.47,
|
||||
"target_served_after_hook_returned": false,
|
||||
"errors_during_outage": 0,
|
||||
"error_kinds": [],
|
||||
"error_window_seconds": 0.0,
|
||||
"restore_hook_seconds": 1.45,
|
||||
"lb_back_up_seconds": 3.05,
|
||||
"target_back_in_rotation_seconds": 3.05,
|
||||
"windows": {
|
||||
"before": {
|
||||
"from_s": 0,
|
||||
"to_s": 5.01,
|
||||
"requests": 1416,
|
||||
"ok": 1416,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 282.9,
|
||||
"write_ok_rps": 164.8,
|
||||
"latency_ms_ok": {
|
||||
"p50": 19.4,
|
||||
"p95": 41.3,
|
||||
"p99": 53.4
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
},
|
||||
"outage_first_10s": {
|
||||
"from_s": 5.01,
|
||||
"to_s": 15.01,
|
||||
"requests": 2431,
|
||||
"ok": 2431,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 243.1,
|
||||
"write_ok_rps": 142.8,
|
||||
"latency_ms_ok": {
|
||||
"p50": 24.8,
|
||||
"p95": 39.6,
|
||||
"p99": 46.3
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
},
|
||||
"outage_rest": {
|
||||
"from_s": 15.01,
|
||||
"to_s": 20.01,
|
||||
"requests": 1154,
|
||||
"ok": 1154,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 230.7,
|
||||
"write_ok_rps": 136.0,
|
||||
"latency_ms_ok": {
|
||||
"p50": 25.4,
|
||||
"p95": 39.9,
|
||||
"p99": 46.5
|
||||
},
|
||||
"instances": [
|
||||
"api-1"
|
||||
]
|
||||
},
|
||||
"after_restore": {
|
||||
"from_s": 20.01,
|
||||
"to_s": 26.3,
|
||||
"requests": 1851,
|
||||
"ok": 1851,
|
||||
"errors": 0,
|
||||
"error_ratio": 0.0,
|
||||
"ok_rps": 293.9,
|
||||
"write_ok_rps": 172.6,
|
||||
"latency_ms_ok": {
|
||||
"p50": 19.8,
|
||||
"p95": 35.8,
|
||||
"p99": 42.1
|
||||
},
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"lb_timeline": [
|
||||
[
|
||||
0.01,
|
||||
[
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
],
|
||||
[
|
||||
6.53,
|
||||
[
|
||||
"api-1"
|
||||
]
|
||||
],
|
||||
[
|
||||
23.06,
|
||||
[
|
||||
"api-1",
|
||||
"api-2"
|
||||
]
|
||||
]
|
||||
],
|
||||
"data": {
|
||||
"confirmed_writes": 4020,
|
||||
"stored_messages": 4020,
|
||||
"missing_or_altered": 0,
|
||||
"duplicate_ids": 0,
|
||||
"duplicate_texts": 0,
|
||||
"same_key_retries": 0,
|
||||
"ok": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"pass": true
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"lab": 4,
|
||||
"workload": "closed-loop POST messages; no automatic retries",
|
||||
"requested_duration_seconds": 20.0,
|
||||
"elapsed_seconds": 20.055,
|
||||
"concurrency": 4,
|
||||
"successful_requests": 5544,
|
||||
"failed_requests": 0,
|
||||
"error_ratio": 0.0,
|
||||
"successful_rps": 276.435,
|
||||
"successful_latency_ms": {
|
||||
"p50": 13.241,
|
||||
"p95": 23.756,
|
||||
"p99": 32.552
|
||||
},
|
||||
"note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead."
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# 2026-11-02T13:24:54Z native sandbox: python3 tests/resilience.py --mode persistence --action-script <restart hook>
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
# hook log: PIDs before/after (postgres, seaweedfs, api x2) + S3 warm-up
|
||||
2026-11-02T13:24:15Z restart begin pg=6347 s3=6937 api=6405,6525
|
||||
{"s3_ready_after_s": 16.4, "last_cycle_s": 1.028, "existing_object_read": true}
|
||||
2026-11-02T13:24:53Z restart end pg=7134 s3=7149 api=7195,7219
|
||||
@@ -0,0 +1,17 @@
|
||||
# 2026-11-02T13:37:06Z | reconcile dry-run
|
||||
$ python -m src.reconcile
|
||||
{
|
||||
"mode": "dry-run",
|
||||
"grace_seconds": 900,
|
||||
"stale_pending": 0,
|
||||
"stale_pending_ids": [],
|
||||
"objects_listed": 238,
|
||||
"orphan_objects": 0,
|
||||
"orphan_objects_within_grace": 0,
|
||||
"orphan_objects_sample": [],
|
||||
"bucket_scan_seconds": 0.036,
|
||||
"ready_rows": 238,
|
||||
"missing_objects": 0,
|
||||
"missing_object_ids": [],
|
||||
"total_seconds": 0.045
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
# 2026-11-02T13:36:49Z | S3 bootstrap, 2nd run on existing bucket (idempotent)
|
||||
$ python -m src.s3_bootstrap
|
||||
{
|
||||
"endpoint_host": "127.0.0.3",
|
||||
"bucket": "messenger-attachments",
|
||||
"checks": [
|
||||
{
|
||||
"check": "api credentials: put/get own bucket",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "anonymous GET object is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "anonymous list bucket is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "anonymous list buckets is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "api credentials cannot create buckets",
|
||||
"ok": true,
|
||||
"detail": "AccessDenied"
|
||||
},
|
||||
{
|
||||
"check": "api credentials cannot delete the bucket",
|
||||
"ok": true,
|
||||
"detail": "AccessDenied"
|
||||
},
|
||||
{
|
||||
"check": "SeaweedFS admin/UI ports are not reachable on the shared network",
|
||||
"ok": true,
|
||||
"detail": "checked [9333, 8888, 8080, 19333, 18888]"
|
||||
}
|
||||
],
|
||||
"bucket_action": "already exists (idempotent no-op)",
|
||||
"ok": true
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"scenario": "S3 outage and recovery",
|
||||
"max_fail_seconds": 15.0,
|
||||
"s3_warmup_seconds": 16.42,
|
||||
"checks": [
|
||||
{
|
||||
"check": "baseline upload 201",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "readiness stays 200 while S3 is down (S3 is not a readiness dependency)",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "text message 201 during S3 outage",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "history 200 during S3 outage",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "attachment metadata 200 (PostgreSQL only)",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "message referencing existing attachment 201",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 -> 503 unavailable",
|
||||
"ok": true,
|
||||
"detail": "503 unavailable in 1.75s"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 failed fast (<= 15s)",
|
||||
"ok": true,
|
||||
"detail": "1.75s"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 has Retry-After",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "upload #2 -> 503 unavailable",
|
||||
"ok": true,
|
||||
"detail": "503 unavailable in 2.31s"
|
||||
},
|
||||
{
|
||||
"check": "upload #2 failed fast (<= 15s)",
|
||||
"ok": true,
|
||||
"detail": "2.31s"
|
||||
},
|
||||
{
|
||||
"check": "upload #2 has Retry-After",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "download -> 503 during outage",
|
||||
"ok": true,
|
||||
"detail": "503 in 0.01s"
|
||||
},
|
||||
{
|
||||
"check": "download failed fast",
|
||||
"ok": true,
|
||||
"detail": "0.01s"
|
||||
},
|
||||
{
|
||||
"check": "session still valid",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "S3 read/write warm-up after start",
|
||||
"ok": true,
|
||||
"detail": "16.42s"
|
||||
},
|
||||
{
|
||||
"check": "old file downloads byte-for-byte after recovery",
|
||||
"ok": true,
|
||||
"detail": "200 0.01s"
|
||||
},
|
||||
{
|
||||
"check": "new upload 201 after recovery (same token, no API restart)",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
}
|
||||
],
|
||||
"pass": true
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"scenario": "S3 outage and recovery",
|
||||
"max_fail_seconds": 15.0,
|
||||
"s3_warmup_seconds": 16.09,
|
||||
"checks": [
|
||||
{
|
||||
"check": "baseline upload 201",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "readiness stays 200 while S3 is down (S3 is not a readiness dependency)",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "text message 201 during S3 outage",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "history 200 during S3 outage",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "attachment metadata 200 (PostgreSQL only)",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "message referencing existing attachment 201",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 -> 503 unavailable",
|
||||
"ok": true,
|
||||
"detail": "503 unavailable in 10.02s"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 failed fast (<= 15s)",
|
||||
"ok": true,
|
||||
"detail": "10.02s"
|
||||
},
|
||||
{
|
||||
"check": "upload #1 has Retry-After",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "upload #2 -> 503 unavailable",
|
||||
"ok": true,
|
||||
"detail": "503 unavailable in 10.01s"
|
||||
},
|
||||
{
|
||||
"check": "upload #2 failed fast (<= 15s)",
|
||||
"ok": true,
|
||||
"detail": "10.01s"
|
||||
},
|
||||
{
|
||||
"check": "upload #2 has Retry-After",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "download -> 503 during outage",
|
||||
"ok": true,
|
||||
"detail": "503 in 5.01s"
|
||||
},
|
||||
{
|
||||
"check": "download failed fast",
|
||||
"ok": true,
|
||||
"detail": "5.01s"
|
||||
},
|
||||
{
|
||||
"check": "session still valid",
|
||||
"ok": true,
|
||||
"detail": "200"
|
||||
},
|
||||
{
|
||||
"check": "S3 read/write warm-up after start",
|
||||
"ok": true,
|
||||
"detail": "16.09s"
|
||||
},
|
||||
{
|
||||
"check": "old file downloads byte-for-byte after recovery",
|
||||
"ok": true,
|
||||
"detail": "200 0.02s"
|
||||
},
|
||||
{
|
||||
"check": "new upload 201 after recovery (same token, no API restart)",
|
||||
"ok": true,
|
||||
"detail": "201"
|
||||
}
|
||||
],
|
||||
"pass": true
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
# 2026-11-02T13:37:07Z | private bucket outside API (anonymous S3 requests), key permissions, admin ports
|
||||
$ python -m src.s3_bootstrap --check-only --sample-from-db
|
||||
{
|
||||
"endpoint_host": "127.0.0.3",
|
||||
"bucket": "messenger-attachments",
|
||||
"checks": [
|
||||
{
|
||||
"check": "api credentials: put/get own bucket",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"check": "anonymous GET object is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "anonymous list bucket is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "anonymous list buckets is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "api credentials cannot create buckets",
|
||||
"ok": true,
|
||||
"detail": "AccessDenied"
|
||||
},
|
||||
{
|
||||
"check": "api credentials cannot delete the bucket",
|
||||
"ok": true,
|
||||
"detail": "AccessDenied"
|
||||
},
|
||||
{
|
||||
"check": "SeaweedFS admin/UI ports are not reachable on the shared network",
|
||||
"ok": true,
|
||||
"detail": "checked [9333, 8888, 8080, 19333, 18888]"
|
||||
},
|
||||
{
|
||||
"check": "anonymous GET of a real attachment object is denied",
|
||||
"ok": true,
|
||||
"detail": "HTTP 403"
|
||||
},
|
||||
{
|
||||
"check": "same object is readable with API credentials and matches sha256",
|
||||
"ok": true,
|
||||
"detail": "111817 bytes"
|
||||
}
|
||||
],
|
||||
"ok": true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# 2026-11-02T13:36:50Z | public smoke
|
||||
$ python3 tests/smoke.py --base-url http://127.0.0.1:8080
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,120 @@
|
||||
# 2026-11-02T13:37:16Z | student tests over HTTP via LB (lab2-4); DB-level tests skip here and run below with DB access
|
||||
$ python3 student-tests/run_all.py --base-url http://127.0.0.1:8080
|
||||
|
||||
== API, auth, concurrency, idempotency tests (DB/expiry tests skip without their env)
|
||||
test_chat_list_pagination (test_api.ApiBehaviorTests.test_chat_list_pagination) ... ok
|
||||
test_cursor_from_other_chat_returns_400 (test_api.ApiBehaviorTests.test_cursor_from_other_chat_returns_400) ... ok
|
||||
test_duplicate_username_returns_409 (test_api.ApiBehaviorTests.test_duplicate_username_returns_409) ... ok
|
||||
test_empty_message_returns_400 (test_api.ApiBehaviorTests.test_empty_message_returns_400) ... ok
|
||||
test_malformed_json_returns_400 (test_api.ApiBehaviorTests.test_malformed_json_returns_400) ... ok
|
||||
test_naive_timestamp_cursor_returns_400 (test_api.ApiBehaviorTests.test_naive_timestamp_cursor_returns_400) ... ok
|
||||
test_outsider_cannot_access_chat (test_api.ApiBehaviorTests.test_outsider_cannot_access_chat) ... ok
|
||||
test_pagination_returns_all_messages_without_duplicates (test_api.ApiBehaviorTests.test_pagination_returns_all_messages_without_duplicates) ... ok
|
||||
test_password_never_returned (test_api.ApiBehaviorTests.test_password_never_returned) ... ok
|
||||
test_registration_without_password_returns_400 (test_api.ApiBehaviorTests.test_registration_without_password_returns_400) ... ok
|
||||
test_sender_id_in_body_rejected (test_api.ApiBehaviorTests.test_sender_id_in_body_rejected) ... ok
|
||||
test_short_password_returns_400 (test_api.ApiBehaviorTests.test_short_password_returns_400) ... ok
|
||||
test_crash_between_put_and_commit_dry_run_then_apply_then_noop (test_attachment_consistency.AttachmentConsistencyTests.test_crash_between_put_and_commit_dry_run_then_apply_then_noop) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_fresh_pending_is_kept (test_attachment_consistency.AttachmentConsistencyTests.test_fresh_pending_is_kept) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_missing_object_is_reported_not_deleted (test_attachment_consistency.AttachmentConsistencyTests.test_missing_object_is_reported_not_deleted) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_orphan_object_deleted_only_after_grace (test_attachment_consistency.AttachmentConsistencyTests.test_orphan_object_deleted_only_after_grace) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_pending_cannot_be_attached (test_attachment_consistency.AttachmentConsistencyTests.test_pending_cannot_be_attached) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_ready_and_referenced_are_never_collected (test_attachment_consistency.AttachmentConsistencyTests.test_ready_and_referenced_are_never_collected) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_aborted_upload_leaves_no_row_and_no_object (test_attachment_consistency.UploadFailureTests.test_aborted_upload_leaves_no_row_and_no_object) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_db_failure_after_put_returns_503_and_deletes_object (test_attachment_consistency.UploadFailureTests.test_db_failure_after_put_returns_503_and_deletes_object) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_process_crash_after_put_is_collected_by_gc (test_attachment_consistency.UploadFailureTests.test_process_crash_after_put_is_collected_by_gc) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_s3_put_failure_returns_503_and_compensates (test_attachment_consistency.UploadFailureTests.test_s3_put_failure_returns_503_and_compensates) ... skipped 'DATABASE_URL and S3 settings are not configured'
|
||||
test_attachment_from_other_chat_is_404_and_nothing_saved (test_attachments.AttachmentTests.test_attachment_from_other_chat_is_404_and_nothing_saved) ... ok
|
||||
test_content_type_with_parameters_is_accepted (test_attachments.AttachmentTests.test_content_type_with_parameters_is_accepted) ... ok
|
||||
test_corrupted_images_are_415 (test_attachments.AttachmentTests.test_corrupted_images_are_415) ... ok
|
||||
test_dangerous_filenames_are_400 (test_attachments.AttachmentTests.test_dangerous_filenames_are_400) ... ok
|
||||
test_exactly_max_size_is_accepted (test_attachments.AttachmentTests.test_exactly_max_size_is_accepted) ... ok
|
||||
test_idempotency_includes_attachment_ids (test_attachments.AttachmentTests.test_idempotency_includes_attachment_ids) ... ok
|
||||
test_invalid_and_unknown_attachment_ids (test_attachments.AttachmentTests.test_invalid_and_unknown_attachment_ids) ... ok
|
||||
test_jpeg_baseline_and_progressive (test_attachments.AttachmentTests.test_jpeg_baseline_and_progressive) ... ok
|
||||
test_message_attachment_validation (test_attachments.AttachmentTests.test_message_attachment_validation) ... ok
|
||||
test_message_with_attachments_visible_to_members (test_attachments.AttachmentTests.test_message_with_attachments_visible_to_members) ... ok
|
||||
test_mime_spoofing_is_415 (test_attachments.AttachmentTests.test_mime_spoofing_is_415) ... ok
|
||||
test_original_variant_and_unknown_variants (test_attachments.AttachmentTests.test_original_variant_and_unknown_variants) ... ok
|
||||
test_outsider_and_unknown_chat_upload_404 (test_attachments.AttachmentTests.test_outsider_and_unknown_chat_upload_404) ... ok
|
||||
test_png_roundtrip_member_reads_outsider_404 (test_attachments.AttachmentTests.test_png_roundtrip_member_reads_outsider_404) ... ok
|
||||
test_too_large_chunked_without_content_length (test_attachments.AttachmentTests.test_too_large_chunked_without_content_length) ... ok
|
||||
test_too_large_with_content_length (test_attachments.AttachmentTests.test_too_large_with_content_length) ... ok
|
||||
test_too_many_pixels (test_attachments.AttachmentTests.test_too_many_pixels) ... ok
|
||||
test_basic_on_business_endpoint_rejected (test_auth.AuthTests.test_basic_on_business_endpoint_rejected) ... ok
|
||||
test_login_with_body_rejected (test_auth.AuthTests.test_login_with_body_rejected)
|
||||
Контракт: вход — только заголовок Basic, без тела. Лишний ввод -> 400, сессии нет. ... ok
|
||||
test_logout_revokes_only_current_session (test_auth.AuthTests.test_logout_revokes_only_current_session) ... ok
|
||||
test_malformed_basic_headers (test_auth.AuthTests.test_malformed_basic_headers) ... ok
|
||||
test_password_with_colon_and_unicode (test_auth.AuthTests.test_password_with_colon_and_unicode) ... ok
|
||||
test_session_shape_and_token_entropy (test_auth.AuthTests.test_session_shape_and_token_entropy) ... ok
|
||||
test_unknown_and_garbage_tokens (test_auth.AuthTests.test_unknown_and_garbage_tokens) ... ok
|
||||
test_wrong_password_and_unknown_user_look_the_same (test_auth.AuthTests.test_wrong_password_and_unknown_user_look_the_same) ... ok
|
||||
test_x_user_id_gives_no_access (test_auth.AuthTests.test_x_user_id_gives_no_access) ... ok
|
||||
test_duplicate_and_missing_caller_rejected (test_concurrency.ChatRollbackTests.test_duplicate_and_missing_caller_rejected) ... ok
|
||||
test_unknown_member_rolls_back_whole_chat (test_concurrency.ChatRollbackTests.test_unknown_member_rolls_back_whole_chat)
|
||||
Чат вставляется первым, затем участники по порядку (сначала сам владелец). ... ok
|
||||
test_same_username_parallel_registration (test_concurrency.RegistrationRaceTests.test_same_username_parallel_registration) ... ok
|
||||
test_session_expires_even_when_cached (test_expiry.ExpiryTests.test_session_expires_even_when_cached) ... skipped 'set EXPIRY_BASE_URL to the short-TTL API instance'
|
||||
test_auth_checked_before_key (test_idempotency.IdempotencyTests.test_auth_checked_before_key) ... ok
|
||||
test_concurrent_same_key_across_replicas_creates_one_message (test_idempotency.IdempotencyTests.test_concurrent_same_key_across_replicas_creates_one_message) ...
|
||||
24 parallel POSTs, one key -> 1 message; replicas: ['api-1', 'api-2']
|
||||
ok
|
||||
test_concurrent_same_key_different_bodies_one_winner (test_idempotency.IdempotencyTests.test_concurrent_same_key_different_bodies_one_winner) ... ok
|
||||
test_failed_access_does_not_burn_key (test_idempotency.IdempotencyTests.test_failed_access_does_not_burn_key) ... ok
|
||||
test_json_formatting_and_key_order_do_not_matter (test_idempotency.IdempotencyTests.test_json_formatting_and_key_order_do_not_matter) ... ok
|
||||
test_key_survives_new_session_of_same_user (test_idempotency.IdempotencyTests.test_key_survives_new_session_of_same_user) ... ok
|
||||
test_missing_or_invalid_key_is_400 (test_idempotency.IdempotencyTests.test_missing_or_invalid_key_is_400) ... ok
|
||||
test_replay_rechecks_session (test_idempotency.IdempotencyTests.test_replay_rechecks_session) ... ok
|
||||
test_scope_is_user_and_chat (test_idempotency.IdempotencyTests.test_scope_is_user_and_chat) ... ok
|
||||
test_sequential_replay_and_conflict (test_idempotency.IdempotencyTests.test_sequential_replay_and_conflict) ... ok
|
||||
test_debt_survives_api_restart (test_session_cache.SessionRevocationCacheTests.test_debt_survives_api_restart)
|
||||
Процесс, выполнивший logout, умер до восстановления связи — новый процесс не доверяет кэшу. ... skipped 'DATABASE_URL is not configured'
|
||||
test_normal_logout_leaves_no_debt (test_session_cache.SessionRevocationCacheTests.test_normal_logout_leaves_no_debt) ... skipped 'DATABASE_URL is not configured'
|
||||
test_revoked_token_rejected_after_partition_heals (test_session_cache.SessionRevocationCacheTests.test_revoked_token_rejected_after_partition_heals) ... skipped 'DATABASE_URL is not configured'
|
||||
test_cleanup_runs_on_one_replica_at_a_time (test_storage_idempotency.StorageIdempotencyTests.test_cleanup_runs_on_one_replica_at_a_time) ... skipped 'DATABASE_URL is not configured'
|
||||
test_conflict_on_different_body (test_storage_idempotency.StorageIdempotencyTests.test_conflict_on_different_body) ... skipped 'DATABASE_URL is not configured'
|
||||
test_expired_key_can_be_reused_and_is_cleaned (test_storage_idempotency.StorageIdempotencyTests.test_expired_key_can_be_reused_and_is_cleaned) ... skipped 'DATABASE_URL is not configured'
|
||||
test_failure_inside_transaction_stores_nothing (test_storage_idempotency.StorageIdempotencyTests.test_failure_inside_transaction_stores_nothing) ... skipped 'DATABASE_URL is not configured'
|
||||
test_threads_same_key_single_insert (test_storage_idempotency.StorageIdempotencyTests.test_threads_same_key_single_insert) ... skipped 'DATABASE_URL is not configured'
|
||||
test_failure_after_inserts_leaves_nothing (test_storage_rollback.StorageRollbackTests.test_failure_after_inserts_leaves_nothing) ... skipped 'DATABASE_URL is not configured'
|
||||
test_migrations_are_idempotent (test_storage_rollback.StorageRollbackTests.test_migrations_are_idempotent) ... skipped 'DATABASE_URL is not configured'
|
||||
test_no_orphan_chats_in_database (test_storage_rollback.StorageRollbackTests.test_no_orphan_chats_in_database) ... skipped 'DATABASE_URL is not configured'
|
||||
test_passwords_stored_as_argon2id (test_storage_rollback.StorageRollbackTests.test_passwords_stored_as_argon2id) ... skipped 'DATABASE_URL is not configured'
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 74 tests in 6.028s
|
||||
|
||||
OK (skipped=23)
|
||||
|
||||
== Concurrent write test
|
||||
PASS: concurrent write test; 10 clients x 10 messages = 100 messages; no lost or duplicate messages
|
||||
|
||||
ALL STUDENT TESTS PASSED
|
||||
# DB-level tests (lab2-3) with direct DB access
|
||||
$ python -m unittest discover -s student-tests -p "test_storage_*.py"; ... -p test_session_cache.py
|
||||
test_cleanup_runs_on_one_replica_at_a_time (test_storage_idempotency.StorageIdempotencyTests.test_cleanup_runs_on_one_replica_at_a_time) ... ok
|
||||
test_conflict_on_different_body (test_storage_idempotency.StorageIdempotencyTests.test_conflict_on_different_body) ... ok
|
||||
test_expired_key_can_be_reused_and_is_cleaned (test_storage_idempotency.StorageIdempotencyTests.test_expired_key_can_be_reused_and_is_cleaned) ... ok
|
||||
test_failure_inside_transaction_stores_nothing (test_storage_idempotency.StorageIdempotencyTests.test_failure_inside_transaction_stores_nothing) ... ok
|
||||
test_threads_same_key_single_insert (test_storage_idempotency.StorageIdempotencyTests.test_threads_same_key_single_insert) ... ok
|
||||
test_failure_after_inserts_leaves_nothing (test_storage_rollback.StorageRollbackTests.test_failure_after_inserts_leaves_nothing) ... ok
|
||||
test_migrations_are_idempotent (test_storage_rollback.StorageRollbackTests.test_migrations_are_idempotent) ... ok
|
||||
test_no_orphan_chats_in_database (test_storage_rollback.StorageRollbackTests.test_no_orphan_chats_in_database) ... ok
|
||||
test_passwords_stored_as_argon2id (test_storage_rollback.StorageRollbackTests.test_passwords_stored_as_argon2id) ... ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 9 tests in 3.022s
|
||||
|
||||
OK
|
||||
test_debt_survives_api_restart (test_session_cache.SessionRevocationCacheTests.test_debt_survives_api_restart)
|
||||
Процесс, выполнивший logout, умер до восстановления связи — новый процесс не доверяет кэшу. ... logout: cache invalidation deferred; positive cache disabled
|
||||
ok
|
||||
test_normal_logout_leaves_no_debt (test_session_cache.SessionRevocationCacheTests.test_normal_logout_leaves_no_debt) ... ok
|
||||
test_revoked_token_rejected_after_partition_heals (test_session_cache.SessionRevocationCacheTests.test_revoked_token_rejected_after_partition_heals) ... logout: cache invalidation deferred; positive cache disabled
|
||||
ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 3 tests in 1.564s
|
||||
|
||||
OK
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"label": "final code; peak via VmHWM and 20ms sampling",
|
||||
"date_utc": "2026-11-02T13:41:45Z",
|
||||
"host": "Linux x86_64, 2 CPU",
|
||||
"source": "/proc VmRSS (20 ms)",
|
||||
"concurrency": 10,
|
||||
"rounds": 3,
|
||||
"file_mib": 9.5,
|
||||
"uploads": 30,
|
||||
"statuses": {
|
||||
"201": 30
|
||||
},
|
||||
"sha256_ok": 30,
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"duration_s": 5.06,
|
||||
"latency_201_s": {
|
||||
"p50": 1.316,
|
||||
"p95": 2.069,
|
||||
"max": 2.088280546000078,
|
||||
"mean": 1.407
|
||||
},
|
||||
"memory": {
|
||||
"pid-9293": {
|
||||
"baseline_mib": 95.5,
|
||||
"peak_mib": 163.4,
|
||||
"growth_mib": 67.9,
|
||||
"samples": 356
|
||||
},
|
||||
"pid-9364": {
|
||||
"baseline_mib": 95.4,
|
||||
"peak_mib": 156.1,
|
||||
"growth_mib": 60.6,
|
||||
"samples": 356
|
||||
}
|
||||
},
|
||||
"process_peak_rss_mib": {
|
||||
"pid-9293": 165.8,
|
||||
"pid-9364": 165.3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"label": "c=20, MAX_CONCURRENT_UPLOADS=4",
|
||||
"date_utc": "2026-11-02T13:11:09Z",
|
||||
"host": "Linux x86_64, 2 CPU",
|
||||
"source": "/proc VmRSS (20 ms)",
|
||||
"concurrency": 20,
|
||||
"rounds": 2,
|
||||
"file_mib": 9.5,
|
||||
"uploads": 40,
|
||||
"statuses": {
|
||||
"201": 40
|
||||
},
|
||||
"sha256_ok": 40,
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"duration_s": 6.14,
|
||||
"latency_201_s": {
|
||||
"p50": 2.159,
|
||||
"p95": 3.077,
|
||||
"max": 3.089563180000141,
|
||||
"mean": 2.079
|
||||
},
|
||||
"memory": {
|
||||
"pid-3762": {
|
||||
"baseline_mib": 114.5,
|
||||
"peak_mib": 161.7,
|
||||
"growth_mib": 47.2,
|
||||
"samples": 387
|
||||
},
|
||||
"pid-3834": {
|
||||
"baseline_mib": 96.5,
|
||||
"peak_mib": 159.1,
|
||||
"growth_mib": 62.6,
|
||||
"samples": 387
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"label": "c=20, MAX_CONCURRENT_UPLOADS=64 (limiter effectively off)",
|
||||
"date_utc": "2026-11-02T13:11:34Z",
|
||||
"host": "Linux x86_64, 2 CPU",
|
||||
"source": "/proc VmRSS (20 ms)",
|
||||
"concurrency": 20,
|
||||
"rounds": 2,
|
||||
"file_mib": 9.5,
|
||||
"uploads": 40,
|
||||
"statuses": {
|
||||
"201": 40
|
||||
},
|
||||
"sha256_ok": 40,
|
||||
"instances": [
|
||||
"api-1",
|
||||
"api-2"
|
||||
],
|
||||
"duration_s": 6.06,
|
||||
"latency_201_s": {
|
||||
"p50": 2.901,
|
||||
"p95": 3.031,
|
||||
"max": 3.03438846999984,
|
||||
"mean": 2.702
|
||||
},
|
||||
"memory": {
|
||||
"pid-4062": {
|
||||
"baseline_mib": 88.2,
|
||||
"peak_mib": 261.6,
|
||||
"growth_mib": 173.4,
|
||||
"samples": 400
|
||||
},
|
||||
"pid-4133": {
|
||||
"baseline_mib": 88.7,
|
||||
"peak_mib": 291.4,
|
||||
"growth_mib": 202.8,
|
||||
"samples": 400
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user