Подключение Postgresql и redis

This commit is contained in:
2026-10-30 15:04:31 +03:00
parent e70fd2bb61
commit 712a359866
46 changed files with 2509 additions and 208 deletions
+2
View File
@@ -0,0 +1,2 @@
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+14
View File
@@ -0,0 +1,14 @@
stop redis
live_redis_down 200
ready_redis_down 503
anon_redis_down 401
bearer_redis_down 503
start redis
stop postgres
live_pg_down 200
ready_pg_down 503
anon_pg_down 401
bearer_pg_down 503
start postgres
bearer_after 200
PASS dependencies
+1
View File
@@ -0,0 +1 @@
ok messenger/internal/store 0.006s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestIntegrationChatRollback
--- PASS: TestIntegrationChatRollback (0.02s)
PASS
ok messenger/internal/store 0.030s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestIntegrationMigrationRerunKeepsRows
--- PASS: TestIntegrationMigrationRerunKeepsRows (0.02s)
PASS
ok messenger/internal/store 0.028s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestIntegrationRedisRoundTrip
--- PASS: TestIntegrationRedisRoundTrip (2.21s)
PASS
ok messenger/internal/session 2.214s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestSessionWrongPasswordLogoutAndIgnoredUserHeader
--- PASS: TestSessionWrongPasswordLogoutAndIgnoredUserHeader (0.01s)
PASS
ok messenger/internal/api 0.012s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestSessionExpires
--- PASS: TestSessionExpires (2.10s)
PASS
ok messenger/internal/api 2.109s
+4
View File
@@ -0,0 +1,4 @@
=== RUN TestIntegrationUsernameRace
--- PASS: TestIntegrationUsernameRace (0.05s)
PASS
ok messenger/internal/store 0.058s
+8
View File
@@ -0,0 +1,8 @@
uname=Linux 7.0.0-31-generic x86_64
nproc=8
mem_kib=7381312
go=go version go1.26.0 linux/amd64
CONTAINER REPOSITORY TAG PLATFORM IMAGE ID SIZE CREATED
messenger-lab2-api-1 messenger-lab2-api latest linux/amd64 53d3e79b608f 5.48MB 14 seconds ago
messenger-lab2-postgres-1 postgres 16.10-bookworm linux/amd64 38471f330eb8 155MB 5 minutes ago
messenger-lab2-redis-1 redis 7.4.6-alpine linux/amd64 3b73847e7287 17.3MB 6 minutes ago
+12
View File
@@ -0,0 +1,12 @@
=== started_at before ===
/messenger-lab2-api-1 2026-10-30T07:05:53.345595506Z
/messenger-lab2-postgres-1 2026-10-30T07:05:47.55799061Z
/messenger-lab2-redis-1 2026-10-30T07:05:47.557221089Z
test -n "scripts/restart.sh"
python3 tests/resilience.py --base-url "http://localhost:8080" --mode persistence --action-script "scripts/restart.sh"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
=== started_at after ===
/messenger-lab2-api-1 2026-10-30T07:06:30.591040874Z
/messenger-lab2-postgres-1 2026-10-30T07:06:30.255241089Z
/messenger-lab2-redis-1 2026-10-30T07:06:30.310922939Z
+4
View File
@@ -0,0 +1,4 @@
rdb_last_bgsave_status:ok
aof_enabled:1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
+2
View File
@@ -0,0 +1,2 @@
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
+7
View File
@@ -0,0 +1,7 @@
big-1|big-1
big-80000|big-80000
chats|104
messages|100000
mid-15000|mid-15000
tiny-sample|tiny-100
users|1
+7
View File
@@ -0,0 +1,7 @@
big-1|big-1
big-80000|big-80000
chats|104
messages|100000
mid-15000|mid-15000
tiny-sample|tiny-100
users|1
+1
View File
@@ -0,0 +1 @@
2026-01-01 00:00:00.050001|c471f25a-9805-4beb-9a46-c9564042507c
+144
View File
@@ -0,0 +1,144 @@
=== recreate bench ===
CREATE TABLE
CREATE TABLE
CREATE INDEX
CREATE TABLE
CREATE INDEX
CREATE TABLE
CREATE INDEX
=== seed uneven 100000 messages ===
INSERT 0 1
INSERT 0 4
INSERT 0 4
INSERT 0 100
INSERT 0 100
INSERT 0 100000
title | messages
----------+----------
big | 80000
mid | 15000
small | 4000
tiny-1 | 10
tiny-10 | 10
tiny-100 | 10
tiny-11 | 10
tiny-12 | 10
(8 rows)
messages_total
----------------
100000
(1 row)
synchronous_commit
--------------------
on
(1 row)
=== cursor in the big chat ===
=== no secondary index: seq scan of the whole table ===
DROP INDEX
=== EXPLAIN seq_scan chat=bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1 ===
ANALYZE
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=4100.97..4106.72 rows=50 width=56) (actual time=11.330..13.785 rows=50 loops=1)
Buffers: shared hit=1248
-> Gather Merge (cost=4100.97..6800.71 rows=23476 width=56) (actual time=11.329..13.780 rows=50 loops=1)
Workers Planned: 1
Workers Launched: 1
Buffers: shared hit=1248
-> Sort (cost=3100.96..3159.65 rows=23476 width=56) (actual time=9.597..9.599 rows=34 loops=2)
Sort Key: created_at, id
Sort Method: top-N heapsort Memory: 28kB
Buffers: shared hit=1248
Worker 0: Sort Method: top-N heapsort Memory: 28kB
-> Parallel Seq Scan on messages (cost=0.00..2321.10 rows=23476 width=56) (actual time=2.023..6.650 rows=20000 loops=2)
Filter: ((chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.050001+00'::timestamp with time zone, 'c471f25a-9805-4beb-9a46-c9564042507c'::uuid)))
Rows Removed by Filter: 30000
Buffers: shared hit=1233
Planning:
Buffers: shared hit=32
Planning Time: 0.152 ms
Execution Time: 13.824 ms
(19 rows)
=== index on (created_at, id) only ===
CREATE INDEX
=== EXPLAIN time_only_big chat=bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1 ===
ANALYZE
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..7.84 rows=50 width=56) (actual time=0.020..0.038 rows=50 loops=1)
Buffers: shared hit=2 read=3
-> Index Scan using messages_time_idx on messages (cost=0.42..5946.46 rows=40067 width=56) (actual time=0.018..0.033 rows=50 loops=1)
Index Cond: (ROW(created_at, id) > ROW('2026-01-01 00:00:00.050001+00'::timestamp with time zone, 'c471f25a-9805-4beb-9a46-c9564042507c'::uuid))
Filter: (chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1'::uuid)
Buffers: shared hit=2 read=3
Planning:
Buffers: shared hit=30 read=1
Planning Time: 0.166 ms
Execution Time: 0.066 ms
(10 rows)
=== EXPLAIN time_only_small chat=bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb3 ===
ANALYZE
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..146.66 rows=50 width=56) (actual time=0.045..0.252 rows=50 loops=1)
Buffers: shared hit=57 read=6
-> Index Scan using messages_time_idx on messages (cost=0.42..5888.31 rows=2013 width=56) (actual time=0.043..0.247 rows=50 loops=1)
Index Cond: (ROW(created_at, id) > ROW('2026-01-01 00:00:00.050001+00'::timestamp with time zone, 'c471f25a-9805-4beb-9a46-c9564042507c'::uuid))
Filter: (chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb3'::uuid)
Rows Removed by Filter: 1245
Buffers: shared hit=57 read=6
Planning:
Buffers: shared hit=29
Planning Time: 0.223 ms
Execution Time: 0.297 ms
(11 rows)
=== insert cost with time index ===
NOTICE: insert_5000_time_index_ms 109.111
DO
DELETE 5000
DROP INDEX
CREATE INDEX
=== EXPLAIN history_big chat=bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1 ===
ANALYZE
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..9.42 rows=50 width=56) (actual time=0.030..0.049 rows=50 loops=1)
Buffers: shared hit=2 read=3
-> Index Scan using messages_history_idx on messages (cost=0.42..7225.92 rows=40147 width=56) (actual time=0.029..0.044 rows=50 loops=1)
Index Cond: ((chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb1'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.050001+00'::timestamp with time zone, 'c471f25a-9805-4beb-9a46-c9564042507c'::uuid)))
Buffers: shared hit=2 read=3
Planning:
Buffers: shared hit=32 read=1
Planning Time: 0.387 ms
Execution Time: 0.089 ms
(9 rows)
=== EXPLAIN history_small chat=bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb3 ===
ANALYZE
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..116.76 rows=50 width=56) (actual time=0.022..0.047 rows=50 loops=1)
Buffers: shared hit=3 read=2
-> Index Scan using messages_history_idx on messages (cost=0.42..4549.26 rows=1955 width=56) (actual time=0.021..0.042 rows=50 loops=1)
Index Cond: ((chat_id = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbb3'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.050001+00'::timestamp with time zone, 'c471f25a-9805-4beb-9a46-c9564042507c'::uuid)))
Buffers: shared hit=3 read=2
Planning:
Buffers: shared hit=27
Planning Time: 0.144 ms
Execution Time: 0.073 ms
(9 rows)
=== insert cost with history index ===
NOTICE: insert_5000_history_index_ms 100.134
DO
DELETE 5000
=== snapshot before dump ===
=== dump and restore ===
CREATE DATABASE
PASS track2
+6
View File
@@ -0,0 +1,6 @@
messages_before=messages|100000
dump_ms=585
restore_ms=646
compare=match
synchronous_commit=on
hypothesis=history index reads one chat range; time-only index filters chat_id after walking created_at