test: reduce `fs-write-optional-params` flakiness · nodejs/node@75b8db4 · GitHub
Skip to content

Commit 75b8db4

Browse files
LiviaMedeirosjuanarbol
authored andcommitted
test: reduce fs-write-optional-params flakiness
PR-URL: #46238 Fixes: #46144 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 91ece41 commit 75b8db4

3 files changed

Lines changed: 56 additions & 37 deletions

File tree

test/parallel/test-fs-promises-write-optional-params.js

Lines changed: 22 additions & 15 deletions

test/parallel/test-fs-write-optional-params.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@ function testValidCb(buffer, options, index, callback) {
2929
const length = options?.length;
3030
const offset = options?.offset;
3131
const dest = path.resolve(tmpdir.path, `rwopt_valid_${index}`);
32-
fs.open(dest, 'w+', common.mustSucceed((fd) => {
32+
fs.open(dest, 'w', common.mustSucceed((fd) => {
3333
fs.write(fd, buffer, options, common.mustSucceed((bytesWritten, bufferWritten) => {
3434
const writeBufCopy = Uint8Array.prototype.slice.call(bufferWritten);
35-
36-
fs.read(fd, buffer, options, common.mustSucceed((bytesRead, bufferRead) => {
37-
const readBufCopy = Uint8Array.prototype.slice.call(bufferRead);
38-
39-
assert.ok(bytesWritten >= bytesRead);
40-
if (length !== undefined && length !== null) {
41-
assert.strictEqual(bytesWritten, length);
42-
}
43-
if (offset === undefined || offset === 0) {
44-
assert.deepStrictEqual(writeBufCopy, readBufCopy);
45-
}
46-
assert.deepStrictEqual(bufferWritten, bufferRead);
47-
fs.close(fd, common.mustSucceed(callback));
35+
fs.close(fd, common.mustSucceed(() => {
36+
fs.open(dest, 'r', common.mustSucceed((fd) => {
37+
fs.read(fd, buffer, options, common.mustSucceed((bytesRead, bufferRead) => {
38+
const readBufCopy = Uint8Array.prototype.slice.call(bufferRead);
39+
40+
assert.ok(bytesWritten >= bytesRead);
41+
if (length !== undefined && length !== null) {
42+
assert.strictEqual(bytesWritten, length);
43+
assert.strictEqual(bytesRead, length);
44+
}
45+
if (offset === undefined || offset === 0) {
46+
assert.deepStrictEqual(writeBufCopy, readBufCopy);
47+
}
48+
assert.deepStrictEqual(bufferWritten, bufferRead);
49+
fs.close(fd, common.mustSucceed(callback));
50+
}));
51+
}));
4852
}));
4953
}));
5054
}));

test/parallel/test-fs-write-sync-optional-params.js

Lines changed: 16 additions & 8 deletions

0 commit comments

Comments
 (0)