From d365425338fd4b06a893b40dfd667b4ae6ffa081 Mon Sep 17 00:00:00 2001 From: Maksimova Snezhana Date: Wed, 28 Oct 2026 23:43:18 +0300 Subject: [PATCH] test: update concurrent test with idempotency key for lab3 --- student-tests/concurrent_test.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/student-tests/concurrent_test.py b/student-tests/concurrent_test.py index f8e46d2..7469c46 100644 --- a/student-tests/concurrent_test.py +++ b/student-tests/concurrent_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -"""10 клиентов × 10 сообщений = 100 уникальных.""" import asyncio import base64 import json @@ -11,11 +10,14 @@ from concurrent.futures import ThreadPoolExecutor BASE = "http://127.0.0.1:8080" PASSWORD = "Example-only-not-a-real-secret-123" - def call(method, path, body=None, token=None): h = {"Accept": "application/json"} if token: h["Authorization"] = f"Bearer {token}" + # ДОБАВЛЯЕМ IDEMPOTENCY-KEY ДЛЯ POST + if method == "POST" and "/messages" in path: + h["Idempotency-Key"] = uuid.uuid4().hex + data = None if body is not None: data = json.dumps(body).encode("utf-8") @@ -29,7 +31,6 @@ def call(method, path, body=None, token=None): payload = e.read() return e.code, (json.loads(payload) if payload else None) - def create_user_and_login(name): s, u = call("POST", "/api/v1/users", {"username": name, "display_name": name, "password": PASSWORD}) @@ -44,7 +45,6 @@ def create_user_and_login(name): session = json.loads(r.read()) return u, session["token"] - def main(): users = [create_user_and_login(f"conc_{i}_{uuid.uuid4().hex[:6]}") for i in range(10)] owner, owner_token = users[0] @@ -86,6 +86,5 @@ def main(): assert len(seen) == 100, f"expected 100, got {len(seen)}" print("PASS: no lost or duplicated messages") - if __name__ == "__main__": main() \ No newline at end of file