From 3fb4f3fe5a18916aa95f8b035ca994c290c173dc Mon Sep 17 00:00:00 2001 From: Heyang Zhou Date: Fri, 22 Dec 2023 05:04:17 +0800 Subject: fix(unstable): kv watch should stop when db is closed (#21665) Fixes #21634. --- cli/tests/unit/kv_test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit/kv_test.ts b/cli/tests/unit/kv_test.ts index 28c913f21..4963882e1 100644 --- a/cli/tests/unit/kv_test.ts +++ b/cli/tests/unit/kv_test.ts @@ -2248,3 +2248,23 @@ dbTest("set with key versionstamp suffix", async (db) => { "expected string, number, bigint, ArrayBufferView, boolean", ); }); + +Deno.test({ + name: "watch should stop when db closed", + async fn() { + const db = await Deno.openKv(":memory:"); + + const watch = db.watch([["a"]]); + const completion = (async () => { + for await (const _item of watch) { + // pass + } + })(); + + setTimeout(() => { + db.close(); + }, 100); + + await completion; + }, +}); -- cgit v1.2.3