Skip to content

Commit 19d6eb9

Browse files
Trotttargos
authored andcommittedFeb 28, 2021
test: fix flaky test-fs-promises-file-handle-read
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. PR-URL: #37371 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 28cbad3 commit 19d6eb9

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed
 

‎test/parallel/test-fs-promises-file-handle-read.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const tmpdir = require('../common/tmpdir');
1313
const assert = require('assert');
1414
const tmpDir = tmpdir.path;
1515

16-
async function read(fileHandle, buffer, offset, length, position) {
17-
return useConf ?
16+
async function read(fileHandle, buffer, offset, length, position, options) {
17+
return options.useConf ?
1818
fileHandle.read({ buffer, offset, length, position }) :
1919
fileHandle.read(buffer, offset, length, position);
2020
}
2121

22-
async function validateRead(data, file) {
22+
async function validateRead(data, file, options) {
2323
const filePath = path.resolve(tmpDir, file);
2424
const buffer = Buffer.from(data, 'utf8');
2525

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

3333
fileHandle.on('close', common.mustCall());
34-
const readAsyncHandle = await read(fileHandle, Buffer.alloc(11), 0, 11, 0);
34+
const readAsyncHandle =
35+
await read(fileHandle, Buffer.alloc(11), 0, 11, 0, options);
3536
assert.deepStrictEqual(data.length, readAsyncHandle.bytesRead);
3637
if (data.length)
3738
assert.deepStrictEqual(buffer, readAsyncHandle.buffer);
@@ -47,28 +48,26 @@ async function validateRead(data, file) {
4748
await streamFileHandle.close();
4849
}
4950

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

5961
assert.strictEqual(readHandle.bytesRead, 0);
6062
}
6163

62-
let useConf = false;
6364

6465
(async function() {
65-
for (const value of [false, true]) {
66-
tmpdir.refresh();
67-
useConf = value;
68-
69-
await validateRead('Hello world', 'tmp-read-file.txt')
70-
.then(validateRead('', 'tmp-read-empty-file.txt'))
71-
.then(validateLargeRead)
72-
.then(common.mustCall());
73-
}
66+
tmpdir.refresh();
67+
await validateRead('Hello world', 'read-file', { useConf: false });
68+
await validateRead('', 'read-empty-file', { useConf: false });
69+
await validateRead('Hello world', 'read-file-conf', { useConf: true });
70+
await validateRead('', 'read-empty-file-conf', { useConf: true });
71+
await validateLargeRead({ useConf: false });
72+
await validateLargeRead({ useConf: true });
7473
})().then(common.mustCall());

0 commit comments

Comments
 (0)