mirror of
https://github.com/denoland/deno
synced 2024-11-05 18:45:24 +00:00
tests: extend readFile file length during read (#12835)
This commit adds some tests that demonstrate that Deno.readFile reads the entire file, even if the read file is extended during read.
This commit is contained in:
parent
86e5238384
commit
429c773a2e
1 changed files with 40 additions and 0 deletions
|
@ -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);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue