Document scaling experiment, measured database boundary and verified failure recovery
This commit is contained in:
@@ -52,7 +52,14 @@ def test_acl_and_unknown_chat(scenario):
|
||||
for cid in [chat["id"], str(uuid.uuid4())]:
|
||||
for suffix in ["", "/messages"]:
|
||||
c.call("GET", f"/api/v1/chats/{cid}{suffix}", 404, actor=eve)
|
||||
c.call("POST", f"/api/v1/chats/{cid}/messages", 404, actor=eve, body={"text": "x"}, headers={"Idempotency-Key": str(uuid.uuid4())})
|
||||
c.call(
|
||||
"POST",
|
||||
f"/api/v1/chats/{cid}/messages",
|
||||
404,
|
||||
actor=eve,
|
||||
body={"text": "x"},
|
||||
headers={"Idempotency-Key": str(uuid.uuid4())},
|
||||
)
|
||||
c.call("GET", "/api/v1/chats/not-a-uuid", 400, actor=alice)
|
||||
|
||||
|
||||
|
||||
+63
-19
@@ -21,7 +21,11 @@ def test_concurrent_idempotency_and_semantic_empty_attachments(shared):
|
||||
|
||||
def post(i):
|
||||
return Client(os.environ["BASE_URL"]).call(
|
||||
"POST", path, 201, schema="Message", actor=alice,
|
||||
"POST",
|
||||
path,
|
||||
201,
|
||||
schema="Message",
|
||||
actor=alice,
|
||||
body={"text": "same", **({"attachment_ids": []} if i % 2 else {})},
|
||||
headers={"Idempotency-Key": key},
|
||||
)
|
||||
@@ -31,29 +35,49 @@ def test_concurrent_idempotency_and_semantic_empty_attachments(shared):
|
||||
assert len({r["json"]["id"] for r in results}) == 1
|
||||
assert len({r["headers"]["X-Instance-Id"] for r in results}) >= 2
|
||||
assert all(r["json"] == results[0]["json"] for r in results)
|
||||
c.call("POST", path, 409, actor=alice, body={"text": "different"},
|
||||
headers={"Idempotency-Key": key})
|
||||
c.call(
|
||||
"POST", path, 409, actor=alice, body={"text": "different"}, headers={"Idempotency-Key": key}
|
||||
)
|
||||
|
||||
|
||||
def test_key_scope_and_acl(shared):
|
||||
c, alice, bob, eve, chat = shared
|
||||
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||
key = uuid.uuid4().hex
|
||||
first = c.call("POST", path, 201, schema="Message", actor=alice, body={"text": "a"},
|
||||
headers={"Idempotency-Key": key})["json"]
|
||||
other = c.call("POST", path, 201, schema="Message", actor=bob, body={"text": "b"},
|
||||
headers={"Idempotency-Key": key})["json"]
|
||||
first = c.call(
|
||||
"POST",
|
||||
path,
|
||||
201,
|
||||
schema="Message",
|
||||
actor=alice,
|
||||
body={"text": "a"},
|
||||
headers={"Idempotency-Key": key},
|
||||
)["json"]
|
||||
other = c.call(
|
||||
"POST",
|
||||
path,
|
||||
201,
|
||||
schema="Message",
|
||||
actor=bob,
|
||||
body={"text": "b"},
|
||||
headers={"Idempotency-Key": key},
|
||||
)["json"]
|
||||
assert first["id"] != other["id"]
|
||||
for _ in range(2):
|
||||
c.call("POST", path, 404, actor=eve, body={"text": "a"},
|
||||
headers={"Idempotency-Key": key})
|
||||
c.call("POST", path, 404, actor=eve, body={"text": "a"}, headers={"Idempotency-Key": key})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", [None, "", "x" * 129, "bad key", "bad/key", "é"])
|
||||
def test_invalid_idempotency_key(shared, key):
|
||||
c, alice, _, _, chat = shared
|
||||
c.call("POST", f"/api/v1/chats/{chat['id']}/messages", 400, actor=alice,
|
||||
body={"text": "x"}, headers={} if key is None else {"Idempotency-Key": key})
|
||||
c.call(
|
||||
"POST",
|
||||
f"/api/v1/chats/{chat['id']}/messages",
|
||||
400,
|
||||
actor=alice,
|
||||
body={"text": "x"},
|
||||
headers={} if key is None else {"Idempotency-Key": key},
|
||||
)
|
||||
|
||||
|
||||
def test_lossless_nul_message_replay_and_history(shared):
|
||||
@@ -61,10 +85,24 @@ def test_lossless_nul_message_replay_and_history(shared):
|
||||
key = uuid.uuid4().hex
|
||||
path = f"/api/v1/chats/{chat['id']}/messages"
|
||||
body = {"text": "abc\u0000def"}
|
||||
first = c.call("POST", path, 201, schema="Message", actor=alice, body=body,
|
||||
headers={"Idempotency-Key": key})["json"]
|
||||
repeat = c.call("POST", path, 201, schema="Message", actor=alice, body=body,
|
||||
headers={"Idempotency-Key": key})["json"]
|
||||
first = c.call(
|
||||
"POST",
|
||||
path,
|
||||
201,
|
||||
schema="Message",
|
||||
actor=alice,
|
||||
body=body,
|
||||
headers={"Idempotency-Key": key},
|
||||
)["json"]
|
||||
repeat = c.call(
|
||||
"POST",
|
||||
path,
|
||||
201,
|
||||
schema="Message",
|
||||
actor=alice,
|
||||
body=body,
|
||||
headers={"Idempotency-Key": key},
|
||||
)["json"]
|
||||
assert first == repeat
|
||||
assert first["text"] == body["text"]
|
||||
history = c.call("GET", path, 200, schema="MessagePage", actor=alice)["json"]["items"]
|
||||
@@ -83,8 +121,9 @@ def test_empty_cursor_and_bad_utf8(shared):
|
||||
c, alice, _, _, chat = shared
|
||||
for path in ["/api/v1/chats", f"/api/v1/chats/{chat['id']}/messages"]:
|
||||
c.call("GET", path + "?cursor=", 400, actor=alice)
|
||||
response = c.call("POST", "/api/v1/users", 400, raw=b"\xff",
|
||||
headers={"Content-Type": "application/json"})
|
||||
response = c.call(
|
||||
"POST", "/api/v1/users", 400, raw=b"\xff", headers={"Content-Type": "application/json"}
|
||||
)
|
||||
assert response["json"]["error"]["code"] == "invalid_request"
|
||||
assert response["headers"]["X-Instance-Id"]
|
||||
c.call("GET", "/api/v1/users/me", 401, headers={"Authorization": "Bearer é"})
|
||||
@@ -97,5 +136,10 @@ def test_login_body_is_rejected(shared):
|
||||
(registration["username"] + ":" + registration["password"]).encode()
|
||||
).decode()
|
||||
for body in [b"{}", b"{bad", b"x"]:
|
||||
c.call("POST", "/api/v1/auth/sessions", 400, raw=body,
|
||||
headers={"Authorization": "Basic " + basic})
|
||||
c.call(
|
||||
"POST",
|
||||
"/api/v1/auth/sessions",
|
||||
400,
|
||||
raw=body,
|
||||
headers={"Authorization": "Basic " + basic},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user