summaryrefslogtreecommitdiff
path: root/cli/tests/unit/write_file_test.ts
diff options
context:
space:
mode:
authorKamil Ogórek <kamil.ogorek@gmail.com>2023-02-11 13:19:13 +0100
committerGitHub <noreply@github.com>2023-02-11 14:19:13 +0200
commit0164959d3441ccfbaaaff20eea2d3ec9fe852373 (patch)
tree833373ac2ef41225a24a48346afc12deccfc78d9 /cli/tests/unit/write_file_test.ts
parent211f49619afd915a2ce56cf0b5da50f640c90f73 (diff)
fix(ops): Always close cancel handles for read_async/write_async (#17736)
Fixes https://github.com/denoland/deno/issues/17734
Diffstat (limited to 'cli/tests/unit/write_file_test.ts')
-rw-r--r--cli/tests/unit/write_file_test.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts
index 78d0f5bad..5f1ffd7a6 100644
--- a/cli/tests/unit/write_file_test.ts
+++ b/cli/tests/unit/write_file_test.ts
@@ -379,6 +379,22 @@ Deno.test(
},
);
+// Test that AbortController's cancel handle is cleaned-up correctly, and do not leak resources.
+Deno.test(
+ { permissions: { read: true, write: true } },
+ async function writeFileWithAbortSignalNotCalled() {
+ const ac = new AbortController();
+ const enc = new TextEncoder();
+ const data = enc.encode("Hello");
+ const filename = Deno.makeTempDirSync() + "/test.txt";
+ await Deno.writeFile(filename, data, { signal: ac.signal });
+ const dataRead = Deno.readFileSync(filename);
+ const dec = new TextDecoder("utf-8");
+ const actual = dec.decode(dataRead);
+ assertEquals(actual, "Hello");
+ },
+);
+
function assertNotExists(filename: string | URL) {
if (pathExists(filename)) {
throw new Error(`The file ${filename} exists.`);