forked from mtusi2026/mtusi2026lab4
lab4: S3, MinIO, reconciler, трек 2, README
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import time
|
||||
import requests
|
||||
|
||||
BASE_URL = "http://localhost:8080"
|
||||
|
||||
|
||||
def get_token(username="stream_tester"):
|
||||
requests.post(f"{BASE_URL}/api/v1/users", json={
|
||||
"username": username, "display_name": "T", "password": "valid_password_123"
|
||||
})
|
||||
resp = requests.post(f"{BASE_URL}/api/v1/auth/sessions",
|
||||
auth=(username, "valid_password_123"))
|
||||
return resp.json()["token"]
|
||||
|
||||
|
||||
def get_chat(token):
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
me = requests.get(f"{BASE_URL}/api/v1/users/me", headers=headers).json()
|
||||
resp = requests.post(f"{BASE_URL}/api/v1/chats", headers=headers, json={
|
||||
"title": "Stream Test", "member_ids": [me["id"]]
|
||||
})
|
||||
return resp.json()["id"]
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print(" STREAM LIMIT TEST")
|
||||
print("=" * 60)
|
||||
token = get_token()
|
||||
chat_id = get_chat(token)
|
||||
print(f"Chat ID: {chat_id}")
|
||||
print("\n=== Отправляем 100 МБ чанками (ожидаем 413, без OOM) ===")
|
||||
|
||||
def gen():
|
||||
for _ in range(100):
|
||||
yield b"0" * (1024 * 1024)
|
||||
|
||||
start = time.monotonic()
|
||||
try:
|
||||
resp = requests.post(
|
||||
f"{BASE_URL}/api/v1/chats/{chat_id}/attachments?filename=big.png",
|
||||
headers={"Authorization": f"Bearer {token}", "Content-Type": "image/png"},
|
||||
data=gen(), timeout=60,
|
||||
)
|
||||
status = resp.status_code
|
||||
except Exception as e:
|
||||
print(f"Ошибка: {e}")
|
||||
status = None
|
||||
elapsed = time.monotonic() - start
|
||||
print(f"Status: {status} (ожидаем 413)")
|
||||
print(f"Время: {elapsed:.2f}s")
|
||||
print("\n" + "=" * 60)
|
||||
if status == 413:
|
||||
print("PASS: потоковый лимит работает, 413")
|
||||
else:
|
||||
print(f"FAIL: ожидался 413, получен {status}")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user