Complete lab

This commit is contained in:
2026-10-09 16:11:06 +03:00
parent d9fe67a8ce
commit 5de73c5475
48 changed files with 1749 additions and 203 deletions
+207
View File
@@ -0,0 +1,207 @@
{
"race_repeats": 5,
"race": {
"naive": [
{
"stale": true,
"read_after_write_ms": 3.362,
"sql": 6,
"history_selects": 1
},
{
"stale": true,
"read_after_write_ms": 2.705,
"sql": 6,
"history_selects": 1
},
{
"stale": true,
"read_after_write_ms": 2.644,
"sql": 6,
"history_selects": 1
},
{
"stale": true,
"read_after_write_ms": 2.601,
"sql": 6,
"history_selects": 1
},
{
"stale": true,
"read_after_write_ms": 2.491,
"sql": 6,
"history_selects": 1
}
],
"versioned": [
{
"stale": false,
"read_after_write_ms": 6.639,
"sql": 7,
"history_selects": 2
},
{
"stale": false,
"read_after_write_ms": 7.862,
"sql": 7,
"history_selects": 2
},
{
"stale": false,
"read_after_write_ms": 8.104,
"sql": 7,
"history_selects": 2
},
{
"stale": false,
"read_after_write_ms": 8.303,
"sql": 7,
"history_selects": 2
},
{
"stale": false,
"read_after_write_ms": 6.384,
"sql": 7,
"history_selects": 2
}
]
},
"benchmark": {
"uncached": [
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 2.84,
"successful_rps": 105.64,
"client_cpu_seconds": 2.878,
"client_peak_rss_mib": 132.52,
"sql": 600,
"history_selects": 300,
"p50_ms": 78.194,
"p95_ms": 108.779,
"p99_ms": 140.556
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 3.164,
"successful_rps": 94.82,
"client_cpu_seconds": 3.148,
"client_peak_rss_mib": 132.52,
"sql": 600,
"history_selects": 300,
"p50_ms": 85.254,
"p95_ms": 126.226,
"p99_ms": 150.227
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 3.134,
"successful_rps": 95.73,
"client_cpu_seconds": 3.142,
"client_peak_rss_mib": 132.52,
"sql": 600,
"history_selects": 300,
"p50_ms": 83.202,
"p95_ms": 121.385,
"p99_ms": 148.622
}
],
"naive": [
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.683,
"successful_rps": 178.21,
"client_cpu_seconds": 1.689,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 39.913,
"p95_ms": 86.212,
"p99_ms": 101.446
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.361,
"successful_rps": 220.37,
"client_cpu_seconds": 1.353,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 28.237,
"p95_ms": 65.387,
"p99_ms": 73.071
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.147,
"successful_rps": 261.59,
"client_cpu_seconds": 1.17,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 22.607,
"p95_ms": 58.264,
"p99_ms": 63.041
}
],
"versioned": [
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.238,
"successful_rps": 242.35,
"client_cpu_seconds": 1.254,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 25.229,
"p95_ms": 60.546,
"p99_ms": 65.823
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.696,
"successful_rps": 176.85,
"client_cpu_seconds": 1.709,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 41.596,
"p95_ms": 73.311,
"p99_ms": 81.611
},
{
"requests": 300,
"concurrency": 8,
"errors": 0,
"seconds": 1.209,
"successful_rps": 248.18,
"client_cpu_seconds": 1.22,
"client_peak_rss_mib": 132.52,
"sql": 300,
"history_selects": 0,
"p50_ms": 24.794,
"p95_ms": 58.879,
"p99_ms": 64.291
}
]
},
"messages": 10000,
"page_size": 100,
"warmup_reads_per_run": 1,
"scope": "store calls; real SQL and Redis; excludes HTTP, sessions and KDF; SQL excludes BEGIN/COMMIT"
}
+4
View File
@@ -0,0 +1,4 @@
Post-experiment snapshot (not peak):
mtusi2026lab2-api-1 CPU=0.22% RAM=58.04MiB / 512MiB
mtusi2026lab2-postgres-1 CPU=7.08% RAM=38.14MiB / 512MiB
mtusi2026lab2-redis-1 CPU=0.30% RAM=3.582MiB / 256MiB
+11
View File
@@ -0,0 +1,11 @@
{
"status": "PASS",
"same_session": true,
"confirmed_messages": 3,
"cold_cache_rebuilt": true,
"read_after_write": true,
"logout_still_401": true,
"recovery_seconds": 1.161,
"redis_start_before_utc": "2026-10-09T12:36:26.91215174Z",
"redis_start_after_utc": "2026-10-09T12:47:22.636577776Z"
}
+38
View File
@@ -0,0 +1,38 @@
Date: 2026-10-09 (Europe/Moscow)
Command: python scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
Command: docker compose exec -T api python tests/smoke.py
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
Command: docker compose exec -T api python -m unittest discover -s student-tests -v
test_chat_rollback ... ok
test_expiry_short_ttl ... ok
test_migrations_repeat ... ok
test_password_logout_and_identity ... ok
test_registration_race ... ok
test_unicode_password ... ok
Ran 6 tests in 8.057s
OK
Command: python tests/resilience.py --mode persistence --action-script scripts/restart.cmd
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
Container start times: evidence/restart.txt
Command: python student-tests/failures.py
PASS redis unavailable: 503; seconds=[3.04, 3.041, 3.036]; anonymous=401; live=200
PASS redis recovered in 6.12s: same session and message
PASS postgres unavailable: 503; seconds=[2.032, 4.034, 4.049]; anonymous=401; live=200
PASS postgres recovered in 6.41s: same session and message
Initial failure test exceeded the HTTP timeout because Docker DNS waited too long
for the stopped service. Fixed with dns_opt timeout:1, attempts:1 on the API.
The timings above are from the successful rerun after this fix.
Final verification after fixes:
python tests/smoke.py --base-url http://127.0.0.1:8080
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
Integration suite repeated: Ran 6 tests in 8.030s; OK.
docker compose ps: api, postgres and redis are healthy.
+12
View File
@@ -0,0 +1,12 @@
Command: docker compose exec -T api python -m scripts.explain_history
Dataset: 10000 messages; page after message 9000; ORM query; limit 51
Limit (cost=0.29..75.12 rows=51 width=1055) (actual time=0.013..0.028 rows=51 loops=1)
Buffers: shared hit=10
-> Index Scan using messages_history_idx on messages (cost=0.29..1535.22 rows=1046 width=1055) (actual time=0.013..0.024 rows=51 loops=1)
Index Cond: ((chat_id = 'ff693a1b-4e99-43c9-bb51-68b5acdd972b'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:09+00'::timestamp with time zone, 'e35d4a84-afe1-4aae-8f55-27be1490c84e'::uuid)))
Buffers: shared hit=10
Planning:
Buffers: shared hit=7
Planning Time: 0.078 ms
Execution Time: 0.056 ms
Synthetic data rolled back.
+20
View File
@@ -0,0 +1,20 @@
SQLAlchemy ORM
Command: docker compose exec -T api python -m unittest discover -s student-tests -v
test_concurrent_writers_do_not_lose_version_increments (test_cache.CacheTests.test_concurrent_writers_do_not_lose_version_increments) ... ok
test_hit_still_checks_membership_and_cache_failure_falls_back (test_cache.CacheTests.test_hit_still_checks_membership_and_cache_failure_falls_back) ... ok
test_http_read_after_write_and_cursor_pages (test_cache.CacheTests.test_http_read_after_write_and_cursor_pages) ... ok
test_late_fill_cannot_restore_old_page (test_cache.CacheTests.test_late_fill_cannot_restore_old_page) ... ok
test_read_after_write_through_another_api_process (test_cache.CacheTests.test_read_after_write_through_another_api_process) ... ok
test_version_rolls_back_with_failed_message (test_cache.CacheTests.test_version_rolls_back_with_failed_message) ... ok
test_migrate_empty_schema_and_preserve_orm_data_on_repeat (test_database.MigrationTests.test_migrate_empty_schema_and_preserve_orm_data_on_repeat) ... ok
test_chat_rollback (test_lab2.Lab2Tests.test_chat_rollback) ... ok
test_expiry_short_ttl (test_lab2.Lab2Tests.test_expiry_short_ttl) ... ok
test_migrations_repeat (test_lab2.Lab2Tests.test_migrations_repeat) ... ok
test_password_logout_and_identity (test_lab2.Lab2Tests.test_password_logout_and_identity) ... ok
test_registration_race (test_lab2.Lab2Tests.test_registration_race) ... ok
test_unicode_password (test_lab2.Lab2Tests.test_unicode_password) ... ok
----------------------------------------------------------------------
Ran 13 tests in 18.089s
OK
+9
View File
@@ -0,0 +1,9 @@
Command: docker compose restart api postgres redis
Before (UTC):
/mtusi2026lab2-api-1 2026-10-09T12:45:16.929905363Z
/mtusi2026lab2-postgres-1 2026-10-09T12:36:54.655202315Z
/mtusi2026lab2-redis-1 2026-10-09T12:47:22.636577776Z
After (UTC):
/mtusi2026lab2-api-1 2026-10-09T12:49:18.471856288Z
/mtusi2026lab2-postgres-1 2026-10-09T12:49:17.844464627Z
/mtusi2026lab2-redis-1 2026-10-09T12:49:17.810209464Z
+13
View File
@@ -0,0 +1,13 @@
Command: python student-tests/failures.py
Container mtusi2026lab2-redis-1 Stopping
Container mtusi2026lab2-redis-1 Stopped
PASS redis unavailable: 503; seconds=[3.043, 3.052, 3.035]; anonymous=401; live=200
Container mtusi2026lab2-redis-1 Starting
Container mtusi2026lab2-redis-1 Started
PASS redis recovered in 6.13s: same session and message
Container mtusi2026lab2-postgres-1 Stopping
Container mtusi2026lab2-postgres-1 Stopped
PASS postgres unavailable: 503; seconds=[2.038, 4.033, 4.027]; anonymous=401; live=200
Container mtusi2026lab2-postgres-1 Starting
Container mtusi2026lab2-postgres-1 Started
PASS postgres recovered in 6.14s: same session and message
+6
View File
@@ -0,0 +1,6 @@
Command: docker compose exec -T api python tests/smoke.py
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
Command: .venv/Scripts/python.exe tests/resilience.py --mode persistence --base-url http://127.0.0.1:8080 --action-script scripts/restart.cmd
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+17
View File
@@ -0,0 +1,17 @@
Command: docker compose exec -T api python -m unittest discover -s student-tests -v
test_hit_still_checks_membership_and_cache_failure_falls_back (test_cache.CacheTests.test_hit_still_checks_membership_and_cache_failure_falls_back) ... ok
test_http_read_after_write_and_cursor_pages (test_cache.CacheTests.test_http_read_after_write_and_cursor_pages) ... ok
test_late_fill_cannot_restore_old_page (test_cache.CacheTests.test_late_fill_cannot_restore_old_page) ... ok
test_read_after_write_through_another_api_process (test_cache.CacheTests.test_read_after_write_through_another_api_process) ... ok
test_version_rolls_back_with_failed_message (test_cache.CacheTests.test_version_rolls_back_with_failed_message) ... ok
test_chat_rollback (test_lab2.Lab2Tests.test_chat_rollback) ... ok
test_expiry_short_ttl (test_lab2.Lab2Tests.test_expiry_short_ttl) ... ok
test_migrations_repeat (test_lab2.Lab2Tests.test_migrations_repeat) ... ok
test_password_logout_and_identity (test_lab2.Lab2Tests.test_password_logout_and_identity) ... ok
test_registration_race (test_lab2.Lab2Tests.test_registration_race) ... ok
test_unicode_password (test_lab2.Lab2Tests.test_unicode_password) ... ok
----------------------------------------------------------------------
Ran 11 tests in 13.089s
OK