This commit is contained in:
2026-10-30 16:39:32 +03:00
parent 0ab3a341aa
commit 117a7783aa
28 changed files with 1049 additions and 37 deletions
+6
View File
@@ -0,0 +1,6 @@
@echo off
cd /d "%~dp0.."
docker compose --env-file .env stop lb api1 api2 redis postgres
if errorlevel 1 exit /b 1
docker compose --env-file .env up -d --wait
exit /b %errorlevel%
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
docker compose --env-file .env stop lb api1 api2 redis postgres
docker compose --env-file .env up -d --wait
+6
View File
@@ -0,0 +1,6 @@
@echo off
cd /d "%~dp0.."
docker compose --env-file .env up -d --no-deps --force-recreate --wait api1
if errorlevel 1 exit /b 1
docker compose --env-file .env up -d --no-deps --force-recreate --wait api2
exit /b %errorlevel%
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
docker compose --env-file .env up -d --no-deps --force-recreate --wait api1
docker compose --env-file .env up -d --no-deps --force-recreate --wait api2
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case "${1:-api1}" in
api1|api2) docker compose --env-file .env up -d "$1" ;;
*) echo "Usage: scripts/start-one.sh api1|api2" >&2; exit 2 ;;
esac
+6
View File
@@ -0,0 +1,6 @@
@echo off
cd /d "%~dp0.."
if "%TARGET_INSTANCE_ID%"=="" set "TARGET_INSTANCE_ID=api1"
if not "%TARGET_INSTANCE_ID%"=="api1" if not "%TARGET_INSTANCE_ID%"=="api2" exit /b 2
docker compose --env-file .env stop %TARGET_INSTANCE_ID%
exit /b %errorlevel%
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case "${TARGET_INSTANCE_ID:-api1}" in
api1|api2) target="${TARGET_INSTANCE_ID:-api1}" ;;
*) echo "Unknown API replica" >&2; exit 2 ;;
esac
docker compose --env-file .env stop "$target"
+42
View File
@@ -0,0 +1,42 @@
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import sys
import threading
from uuid import uuid4
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
from client import Client, check
def main():
client = Client()
alice, _, _, chat = client.bootstrap()
key = uuid4().hex
path = "/api/v1/chats/" + chat["id"] + "/messages"
text = "Проверка одновременного повтора " + key
barrier = threading.Barrier(12)
def send(_):
local = Client(timeout=10)
barrier.wait(timeout=10)
response = local.message(alice, chat, text, key=key)
return response["json"], response["headers"]["X-Instance-Id"]
with ThreadPoolExecutor(max_workers=12) as workers:
results = list(workers.map(send, range(12)))
ids = {message["id"] for message, _ in results}
instances = {instance for _, instance in results}
check(len(ids) == 1, "Повтор создал несколько сообщений")
check(len(instances) == 2, "Не удалось проверить обе реплики")
check(all(result[0] == results[0][0] for result in results), "Ответы различаются")
client.call("POST", path, 409, actor=alice, body={"text": "Другой текст"},
headers={"Idempotency-Key": key})
page = client.call("GET", path + "?limit=100", actor=alice, schema="MessagePage")["json"]
check(sum(item["id"] in ids for item in page["items"]) == 1,
"В истории найден дубль сообщения")
print("PASS: 12 параллельных запросов; 2 реплики; 1 сообщение; повтор с другим текстом — 409")
if __name__ == "__main__":
main()