Skip to content

Commit

Permalink
test: deflake test-fs-read-optional-params
Browse files Browse the repository at this point in the history
If `fs.read()` is called without specifying the `position` option, data
will be read from the current file position. There is another concurrent
`fs.read()` call before the test for no options object which might
invalidate the test expectations.

Run the test for no options object first.

PR-URL: #37991
Fixes: #37946
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
lpinca authored and MylesBorins committed Apr 5, 2021
1 parent 6d28a24 commit 0db1a1e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/parallel/test-fs-read-optional-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const expected = Buffer.from('xyz\n');
const defaultBufferAsync = Buffer.alloc(16384);
const bufferAsOption = Buffer.allocUnsafe(expected.length);

// Test passing in an empty options object
fs.read(fd, { position: 0 }, common.mustCall((err, bytesRead, buffer) => {
// Test not passing in any options object
fs.read(fd, common.mustCall((err, bytesRead, buffer) => {
assert.strictEqual(bytesRead, expected.length);
assert.deepStrictEqual(defaultBufferAsync.length, buffer.length);
}));

// Test not passing in any options object
fs.read(fd, common.mustCall((err, bytesRead, buffer) => {
// Test passing in an empty options object
fs.read(fd, { position: 0 }, common.mustCall((err, bytesRead, buffer) => {
assert.strictEqual(bytesRead, expected.length);
assert.deepStrictEqual(defaultBufferAsync.length, buffer.length);
}));
Expand Down

0 comments on commit 0db1a1e

Please sign in to comment.