Заполнить отчёт и доказательства лабораторной 2
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# Bootstrap from empty volumes: make destroy && make secrets up
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
$ make up
|
||||
Network mtusi2026lab2_default Created
|
||||
Volume mtusi2026lab2_pgdata Created
|
||||
Volume mtusi2026lab2_valkeydata Created
|
||||
Container mtusi2026lab2-valkey-1 Created
|
||||
Container mtusi2026lab2-postgres-1 Created
|
||||
Container mtusi-messenger-lab2 Created
|
||||
Container mtusi2026lab2-postgres-1 Started
|
||||
Container mtusi2026lab2-valkey-1 Started
|
||||
Container mtusi2026lab2-postgres-1 Healthy
|
||||
Container mtusi2026lab2-valkey-1 Healthy
|
||||
Container mtusi-messenger-lab2 Started
|
||||
Container mtusi2026lab2-postgres-1 Healthy
|
||||
Container mtusi2026lab2-valkey-1 Healthy
|
||||
Container mtusi-messenger-lab2 Healthy
|
||||
|
||||
$ docker compose ps
|
||||
SERVICE IMAGE STATUS PORTS
|
||||
api mtusi-messenger:lab2 Up 6 seconds (healthy) 127.0.0.1:8080->8080/tcp
|
||||
postgres postgres:18.6-alpine3.24@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 Up 11 seconds (healthy) 5432/tcp
|
||||
valkey valkey/valkey:9.1.2-alpine3.24@sha256:48332870af354a799964c0012ae1194a0bf2bf894eb508f945810596dc2d8d11 Up 11 seconds (healthy) 6379/tcp
|
||||
|
||||
$ docker compose logs api | grep -E "schema ready|starting"
|
||||
{"time":"2026-10-06T13:00:02.672577874Z","level":"INFO","msg":"schema ready","applied_migrations":[1]}
|
||||
{"time":"2026-10-06T13:00:02.689453662Z","level":"INFO","msg":"starting","env":"lab","addr":"0.0.0.0:8080","shutdown_timeout":"8s","session_ttl":"1h0m0s"}
|
||||
|
||||
$ psql \dt and \di (schema created by the migration)
|
||||
List of tables
|
||||
Schema | Name | Type | Owner
|
||||
--------+------------------+-------+-----------
|
||||
public | chat_members | table | messenger
|
||||
public | chats | table | messenger
|
||||
public | goose_db_version | table | messenger
|
||||
public | messages | table | messenger
|
||||
public | users | table | messenger
|
||||
(5 rows)
|
||||
|
||||
List of indexes
|
||||
Schema | Name | Type | Owner | Table
|
||||
--------+----------------------------+-------+-----------+------------------
|
||||
public | chat_members_pkey | index | messenger | chat_members
|
||||
public | chat_members_user_chat_idx | index | messenger | chat_members
|
||||
public | chats_pkey | index | messenger | chats
|
||||
public | goose_db_version_pkey | index | messenger | goose_db_version
|
||||
public | messages_pkey | index | messenger | messages
|
||||
public | users_pkey | index | messenger | users
|
||||
public | users_username_key | index | messenger | users
|
||||
(7 rows)
|
||||
|
||||
|
||||
$ valkey-cli CONFIG GET (persistence of the session store)
|
||||
appendonly yes
|
||||
appendfsync always
|
||||
save
|
||||
maxmemory 268435456
|
||||
maxmemory-policy noeviction
|
||||
|
||||
$ second start: migrations are a no-op
|
||||
{"time":"2026-10-06T13:00:12.891361865Z","level":"INFO","msg":"schema ready","applied_migrations":[]}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"base_url": "http://localhost:8080",
|
||||
"started_at": "2026-10-06T13:01:23.3690872Z",
|
||||
"clients": 10,
|
||||
"per_client": 10,
|
||||
"expected_messages": 100,
|
||||
"created_201": 100,
|
||||
"failed_posts": 0,
|
||||
"listed_messages": 100,
|
||||
"unique_ids": 100,
|
||||
"created_but_not_listed": 0,
|
||||
"history_ordered_by_id": true,
|
||||
"pages_read": 1,
|
||||
"elapsed_seconds": 0.1081132,
|
||||
"passed": true
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
# Dependency outages on the stand (request deadline 5 s, dial/connect 1 s)
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
baseline GET /users/me: 200
|
||||
|
||||
$ docker compose stop valkey
|
||||
{"error":{"code":"unavailable","message":"session store unavailable","request_id":"6dc8e40f8ed60f3d3e32c65da449744e"}}
|
||||
|
||||
-> 503 in 1.223578s
|
||||
POST /auth/sessions: 503 in 1.235624s
|
||||
POST /users (PostgreSQL only): 201
|
||||
{"error":{"code":"unavailable","message":"valkey is unavailable","request_id":"99a17ea0c0423c3142e004f27e09f739"}}
|
||||
|
||||
-> 503
|
||||
api log:
|
||||
{"time":"2026-10-06T13:01:03.639113985Z","level":"ERROR","msg":"request failed","request_id":"99a17ea0c0423c3142e004f27e09f739","error":"valkey is unavailable","cause":"dial tcp: lookup valkey: i/o timeout"}
|
||||
after docker compose start valkey, same token: 200 (session survived via AOF)
|
||||
|
||||
$ docker compose stop postgres
|
||||
{"error":{"code":"unavailable","message":"database unavailable","request_id":"eeb05d0a51641fb655e0f516f3704b67"}}
|
||||
|
||||
-> 503 in 0.230062s
|
||||
{"error":{"code":"unavailable","message":"postgres is unavailable","request_id":"1df2b60f6d15c835ed4549601fba01d5"}}
|
||||
|
||||
-> 503
|
||||
api log:
|
||||
{"time":"2026-10-06T13:01:10.362999264Z","level":"ERROR","msg":"request failed","request_id":"1df2b60f6d15c835ed4549601fba01d5","error":"postgres is unavailable","cause":"failed to connect to `user=messenger database=messenger`: hostname resolving error: lookup postgres on 127.0.0.11:53: dial udp 127.0.0.11:53: i/o timeout"}
|
||||
after docker compose start postgres: 200
|
||||
GET /health/ready: 200
|
||||
@@ -0,0 +1,12 @@
|
||||
# Session expiry with SESSION_TTL_SECONDS=2
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
api SESSION_TTL_SECONDS=2
|
||||
GET /users/me right after login: 200
|
||||
GET /users/me 3 s later:
|
||||
HTTP/1.1 401 Unauthorized
|
||||
Www-Authenticate: Bearer realm="messenger"
|
||||
{"error":{"code":"unauthorized","message":"a valid bearer token is required","request_id":"30f35aed484df88d7c07e7ee17e2a92a"}}
|
||||
|
||||
api restored with SESSION_TTL_SECONDS=3600
|
||||
@@ -0,0 +1,61 @@
|
||||
# EXPLAIN (ANALYZE, BUFFERS) of the history query: make explain
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
big_chat_messages | all_messages
|
||||
-------------------+--------------
|
||||
12000 | 102003
|
||||
(1 row)
|
||||
|
||||
|
||||
== First page: no cursor, limit 50 (+1 row that tells whether a next page exists)
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..23.86 rows=51 width=67) (actual time=0.020..0.077 rows=51.00 loops=1)
|
||||
Buffers: shared hit=51
|
||||
-> Index Scan using messages_pkey on messages (cost=0.42..5535.89 rows=12045 width=67) (actual time=0.018..0.072 rows=51.00 loops=1)
|
||||
Index Cond: ((chat_id = '01a1114d-de5d-7f2e-8176-990d37b9797e'::uuid) AND (id > '00000000-0000-0000-0000-000000000000'::uuid))
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=51
|
||||
Planning:
|
||||
Buffers: shared hit=17
|
||||
Planning Time: 0.327 ms
|
||||
Execution Time: 0.101 ms
|
||||
(10 rows)
|
||||
|
||||
|
||||
== Deep page: cursor after the 10 001st message of the chat
|
||||
QUERY PLAN
|
||||
----------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=0.42..185.00 rows=51 width=67) (actual time=0.021..0.033 rows=51.00 loops=1)
|
||||
Buffers: shared hit=6
|
||||
-> Index Scan using messages_pkey on messages (cost=0.42..655.49 rows=181 width=67) (actual time=0.020..0.029 rows=51.00 loops=1)
|
||||
Index Cond: ((chat_id = '01a1114d-de5d-7f2e-8176-990d37b9797e'::uuid) AND (id > '01a1114d-e03e-797e-bdd0-3cb5b8cb3079'::uuid))
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.093 ms
|
||||
Execution Time: 0.050 ms
|
||||
(8 rows)
|
||||
|
||||
|
||||
== For contrast, OFFSET pagination of the same page reads every skipped row
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (cost=2837.94..2838.07 rows=51 width=67) (actual time=4.491..4.496 rows=51.00 loops=1)
|
||||
Buffers: shared hit=495
|
||||
-> Sort (cost=2812.94..2843.06 rows=12047 width=67) (actual time=3.874..4.232 rows=10052.00 loops=1)
|
||||
Sort Key: id
|
||||
Sort Method: quicksort Memory: 1978kB
|
||||
Buffers: shared hit=495
|
||||
-> Bitmap Heap Scan on messages (cost=585.78..1996.37 rows=12047 width=67) (actual time=0.422..1.796 rows=12000.00 loops=1)
|
||||
Recheck Cond: (chat_id = '01a1114d-de5d-7f2e-8176-990d37b9797e'::uuid)
|
||||
Heap Blocks: exact=363
|
||||
Buffers: shared hit=495
|
||||
-> Bitmap Index Scan on messages_pkey (cost=0.00..582.77 rows=12047 width=0) (actual time=0.386..0.386 rows=12000.00 loops=1)
|
||||
Index Cond: (chat_id = '01a1114d-de5d-7f2e-8176-990d37b9797e'::uuid)
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=132
|
||||
Planning Time: 0.043 ms
|
||||
Execution Time: 4.629 ms
|
||||
(16 rows)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Persistence: make test-persistence ACTION_SCRIPT=scripts/restart.cmd (scripts/restart.sh on Linux)
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
== containers before
|
||||
/mtusi-messenger-lab2 started=2026-10-06T13:00:12.720916013Z status=running
|
||||
/mtusi2026lab2-postgres-1 started=2026-10-06T12:59:56.582818179Z status=running
|
||||
/mtusi2026lab2-valkey-1 started=2026-10-06T12:59:56.579702461Z status=running
|
||||
|
||||
$ make test-persistence ACTION_SCRIPT=scripts/restart.cmd PYTHON=python
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
|
||||
== containers after (every StartedAt changed: all three processes were restarted, volumes kept)
|
||||
/mtusi-messenger-lab2 started=2026-10-06T13:00:28.600983618Z status=running
|
||||
/mtusi2026lab2-postgres-1 started=2026-10-06T13:00:22.758610805Z status=running
|
||||
/mtusi2026lab2-valkey-1 started=2026-10-06T13:00:22.751213945Z status=running
|
||||
@@ -0,0 +1,9 @@
|
||||
# Public checks: make check, make test
|
||||
# date: 2026-10-06T12:59:03Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1, Python 3.13.1
|
||||
|
||||
$ make check PYTHON=python
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
|
||||
$ make test PYTHON=python
|
||||
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,49 @@
|
||||
# Automated tests against real PostgreSQL and Valkey (testcontainers): go test -race -v
|
||||
# date: 2026-10-06T13:02:19Z, commit: 949622e (branch solution/bpi2301-bakulin)
|
||||
# host: Windows 11, Docker Desktop 28.5.1 (4 CPU, 4111327232 bytes RAM), Go go1.27.1
|
||||
# full suite: make unit (go test -race -count=1 ./...), 16 packages ok
|
||||
|
||||
--- PASS: TestRegisterUserShapeAndConflicts (0.31s)
|
||||
--- PASS: TestConcurrentSendsProduceExactlyUniqueMessages (1.92s)
|
||||
--- PASS: TestLoginReturnsBearerSession (0.35s)
|
||||
--- PASS: TestLoginFailuresAreUniformBasicChallenges (0.43s)
|
||||
--- PASS: TestLoginAcceptsColonAndUnicodePasswords (0.14s)
|
||||
--- PASS: TestProtectedRoutesAcceptOnlyBearer (0.26s)
|
||||
--- PASS: TestLogoutRevokesOnlyTheCurrentToken (0.19s)
|
||||
--- PASS: TestSessionExpiresAfterTTL (1.35s)
|
||||
--- PASS: TestValkeyOutageAnswers503 (3.98s)
|
||||
--- PASS: TestPostgresOutageAnswers503 (4.06s)
|
||||
--- PASS: TestHungPostgresAnswers503WithinTheRequestTimeout (5.45s)
|
||||
ok messenger/internal/app 29.152s
|
||||
--- PASS: TestLoginIssuesOpaqueTokenBackedByStoredSession (0.20s)
|
||||
--- PASS: TestLoginWithBadCredentialsCreatesNoSession (0.30s)
|
||||
--- PASS: TestAuthenticateResolvesTheOwner (0.27s)
|
||||
--- PASS: TestLogoutRevokesOnlyThatSession (0.36s)
|
||||
--- PASS: TestSessionExpiresAfterTTL (1.34s)
|
||||
ok messenger/internal/auth 13.245s
|
||||
--- PASS: TestCreateRollsBackWhenMemberInsertFails (0.08s)
|
||||
--- PASS: TestConcurrentAppendsKeepEveryMessage (0.21s)
|
||||
ok messenger/internal/chat/store 9.320s
|
||||
--- PASS: TestKindOfDefaultsToInternal (0.00s)
|
||||
ok messenger/internal/platform/apperr 1.572s
|
||||
--- PASS: TestDefaults (0.02s)
|
||||
--- PASS: TestSecretFilesAreRequiredAndNeverEchoed (0.07s)
|
||||
--- PASS: TestOverrides (0.02s)
|
||||
--- PASS: TestInvalidValuesAreReported (0.09s)
|
||||
ok messenger/internal/platform/config 1.801s
|
||||
--- PASS: TestUnavailableCauseIsLoggedButNotReturned (0.06s)
|
||||
--- PASS: TestTimeoutBoundsTheRequestContext (0.05s)
|
||||
ok messenger/internal/platform/httpx 5.748s
|
||||
--- PASS: TestMigrateIsRepeatable (0.01s)
|
||||
--- PASS: TestPoolAppliesLimitsAndTimeouts (0.01s)
|
||||
--- PASS: TestClassifyMarksUnreachableDatabaseAsUnavailable (0.00s)
|
||||
--- PASS: TestClassifyRealConnectFailure (0.00s)
|
||||
ok messenger/internal/platform/postgres 9.271s
|
||||
--- PASS: TestRegisterStoresUserWithPasswordHash (0.11s)
|
||||
--- PASS: TestRegisterRejectsInvalidInputAndStoresNothing (0.02s)
|
||||
--- PASS: TestRegisterReportsDuplicateAsConflict (0.21s)
|
||||
--- PASS: TestConcurrentRegistrationOfOneUsernameHasOneWinner (0.30s)
|
||||
--- PASS: TestExistingIDsReturnsOnlyRegistered (0.27s)
|
||||
--- PASS: TestAuthenticateChecksPassword (0.16s)
|
||||
--- PASS: TestAuthenticateFailuresLookTheSame (0.39s)
|
||||
ok messenger/internal/user 10.562s
|
||||
Reference in New Issue
Block a user