forked from mtusi2026/mtusi2026lab7
тесты и healthcheck устойчивее к медленному хосту: время пробы внутри контейнера, healthcheck timeout 5 с, дочитывание TLS-ответа, grace уборщика 15 с
This commit is contained in:
@@ -60,7 +60,19 @@ def raw_upload(token: str, chat_id: str, declared: int, body: bytes, *, wait_ans
|
||||
sock.close()
|
||||
return b""
|
||||
time.sleep(wait_answer)
|
||||
answer = sock.recv(65536)
|
||||
answer = b""
|
||||
sock.settimeout(5)
|
||||
try:
|
||||
while chunk := sock.recv(65536): # lab 7: TLS delivers headers and body in separate records
|
||||
answer += chunk
|
||||
if b"\r\n\r\n" in answer:
|
||||
head, _, body = answer.partition(b"\r\n\r\n")
|
||||
length = next((int(line.split(b":", 1)[1]) for line in head.split(b"\r\n")
|
||||
if line.lower().startswith(b"content-length:")), None)
|
||||
if length is not None and len(body) >= length:
|
||||
break
|
||||
except (TimeoutError, OSError):
|
||||
pass
|
||||
sock.close()
|
||||
return answer
|
||||
|
||||
@@ -84,14 +96,16 @@ def test_crash_after_staging_before_job_is_cleaned_by_janitor(api):
|
||||
(object first) and then the intent row; no job, no message ever existed."""
|
||||
alice = api.user("alice")
|
||||
chat = api.chat(alice)
|
||||
with api_with_env(API_FAULT_POINTS="after_s3_put", PENDING_GRACE_SECONDS="3", JANITOR_INTERVAL_SECONDS="1"):
|
||||
# grace 15 s: the checks below go through docker exec (seconds each on a loaded host) and must
|
||||
# see the orphan BEFORE the janitor may remove it.
|
||||
with api_with_env(API_FAULT_POINTS="after_s3_put", PENDING_GRACE_SECONDS="15", JANITOR_INTERVAL_SECONDS="1"):
|
||||
assert api.upload(alice, chat, SAMPLE, 503).json()["error"]["code"] == "unavailable"
|
||||
[(attachment_id, status, key)] = rows_of_chat(chat["id"])
|
||||
assert status == "pending" and s3_size(key, "staging") == len(SAMPLE) # the orphan-to-be exists
|
||||
assert jobs_of(attachment_id) == (0, 0) # no job, no outbox row
|
||||
api.call("GET", f"/api/v1/attachments/{attachment_id}", 404, token=alice["token"]) # invisible
|
||||
api.post_message(alice, chat, {"text": "", "attachment_ids": [attachment_id]}, 404) # not attachable
|
||||
wait_for(lambda: rows_of_chat(chat["id"]) == [], 30, "janitor did not remove the stale intent")
|
||||
wait_for(lambda: rows_of_chat(chat["id"]) == [], 60, "janitor did not remove the stale intent")
|
||||
assert s3_size(key, "staging") is None # object removed first
|
||||
# Normal configuration again: an upload in the same chat works and is not touched.
|
||||
att = api.upload(alice, chat, SAMPLE).json()
|
||||
|
||||
Reference in New Issue
Block a user