summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/read_file_test.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts
index 0ad8dd908..9b8f5e6df 100644
--- a/cli/tests/unit/read_file_test.ts
+++ b/cli/tests/unit/read_file_test.ts
@@ -1,4 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+import { writeAllSync } from "../../../test_util/std/io/util.ts";
import {
assert,
assertEquals,
@@ -115,3 +116,42 @@ unitTest(
});
},
);
+
+unitTest(
+ { permissions: { read: true, write: true } },
+ async function readFileExtendedDuringRead() {
+ // Write 128MB file
+ const filename = Deno.makeTempDirSync() + "/test.txt";
+ const data = new Uint8Array(1024 * 1024 * 128);
+ Deno.writeFileSync(filename, data);
+ const promise = Deno.readFile(filename);
+ queueMicrotask(() => {
+ // Append 128MB to file
+ const f = Deno.openSync(filename, { append: true });
+ writeAllSync(f, data);
+ f.close();
+ });
+ const read = await promise;
+ assertEquals(read.byteLength, data.byteLength * 2);
+ },
+);
+
+unitTest(
+ { permissions: { read: true, write: true } },
+ async function readFile0LengthExtendedDuringRead() {
+ // Write 0 byte file
+ const filename = Deno.makeTempDirSync() + "/test.txt";
+ const first = new Uint8Array(0);
+ const second = new Uint8Array(1024 * 1024 * 128);
+ Deno.writeFileSync(filename, first);
+ const promise = Deno.readFile(filename);
+ queueMicrotask(() => {
+ // Append 128MB to file
+ const f = Deno.openSync(filename, { append: true });
+ writeAllSync(f, second);
+ f.close();
+ });
+ const read = await promise;
+ assertEquals(read.byteLength, second.byteLength);
+ },
+);