Skip to content

Commit

Permalink
test: fix flaky test-fs-promises-file-handle-read
Browse files Browse the repository at this point in the history
tmpdir.refresh() cannot be called multiple times reliably on Raspberry
Pi in CI because NFS might optimistically report a path as
removed before it actually is. At least, that's what I think is going
on. Anyway, tmpdir.refresh() is generally designed to be called once,
so let's just call it once.
  • Loading branch information
Trott committed Feb 14, 2021
1 parent bcb1964 commit dd48700
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/parallel/test-fs-promises-file-handle-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const tmpDir = tmpdir.path;

async function read(fileHandle, buffer, offset, length, position) {
return useConf ?
async function read(fileHandle, buffer, offset, length, position, options) {
return options.useConf ?
fileHandle.read({ buffer, offset, length, position }) :
fileHandle.read(buffer, offset, length, position);
}

async function validateRead(data, file) {
async function validateRead(data, file, options) {
const filePath = path.resolve(tmpDir, file);
const buffer = Buffer.from(data, 'utf8');

Expand All @@ -31,7 +31,8 @@ async function validateRead(data, file) {
fs.closeSync(fd);

fileHandle.on('close', common.mustCall());
const readAsyncHandle = await read(fileHandle, Buffer.alloc(11), 0, 11, 0);
const readAsyncHandle =
await read(fileHandle, Buffer.alloc(11), 0, 11, 0, options);
assert.deepStrictEqual(data.length, readAsyncHandle.bytesRead);
if (data.length)
assert.deepStrictEqual(buffer, readAsyncHandle.buffer);
Expand All @@ -47,28 +48,27 @@ async function validateRead(data, file) {
await streamFileHandle.close();
}

async function validateLargeRead() {
async function validateLargeRead(options) {
// Reading beyond file length (3 in this case) should return no data.
// This is a test for a bug where reads > uint32 would return data
// from the current position in the file.
const filePath = fixtures.path('x.txt');
const fileHandle = await open(filePath, 'r');
const pos = 0xffffffff + 1; // max-uint32 + 1
const readHandle = await read(fileHandle, Buffer.alloc(1), 0, 1, pos);
const readHandle =
await read(fileHandle, Buffer.alloc(1), 0, 1, pos, options);

assert.strictEqual(readHandle.bytesRead, 0);
}

let useConf = false;

(async function() {
for (const value of [false, true]) {
tmpdir.refresh();
useConf = value;

await validateRead('Hello world', 'tmp-read-file.txt')
.then(validateRead('', 'tmp-read-empty-file.txt'))
.then(validateLargeRead)
tmpdir.refresh();
await validateRead('Hello world', 'read-file', { useConf: false })
.then(validateRead('', 'read-empty-file', { useConf: false }))
.then(validateRead('Hello world', 'read-file-conf', { useConf: true }))
.then(validateRead('', 'read-empty-file-conf', { useConf: true }))
.then(validateLargeRead({ useConf: false }))
.then(validateLargeRead({ useConf: true }))
.then(common.mustCall());
}
})().then(common.mustCall());

0 comments on commit dd48700

Please sign in to comment.