summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
authorHeyang Zhou <zhy20000919@hotmail.com>2023-09-07 15:07:04 +0800
committerGitHub <noreply@github.com>2023-09-07 15:07:04 +0800
commit01a761f1d4f7ff4943fbf80464a276b434d8a8f7 (patch)
tree6dc4a065f46a2bbaa91ecac9b265ef9910d22a35 /cli/tests/unit
parent2cbd1b40cb4392b6a4f6b2e7315e610f488d66b7 (diff)
chore(ext/kv): limit total key size in an atomic op to 80 KiB (#20395)
Keys are expensive metadata. We track it for various purposes, e.g. transaction conflict check, and key expiration. This patch limits the total key size in an atomic operation to 80 KiB (81920 bytes). This helps ensure efficiency in implementations.
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/kv_test.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts
index de764cf80..ea1e328bc 100644
--- a/cli/tests/unit/kv_test.ts
+++ b/cli/tests/unit/kv_test.ts
@@ -1283,6 +1283,21 @@ dbTest("total mutation size limit", async (db) => {
);
});
+dbTest("total key size limit", async (db) => {
+ const longString = new Array(1100).fill("a").join("");
+ const keys: Deno.KvKey[] = new Array(80).fill(0).map(() => [longString]);
+
+ const atomic = db.atomic();
+ for (const key of keys) {
+ atomic.set(key, "foo");
+ }
+ await assertRejects(
+ () => atomic.commit(),
+ TypeError,
+ "total key size too large (max 81920 bytes)",
+ );
+});
+
dbTest("keys must be arrays", async (db) => {
await assertRejects(
// @ts-expect-error invalid type