Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: avoid race in file write stream handle tests #44380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions test/parallel/test-fs-write-stream-file-handle-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, 'write_stream_filehandle_test.txt');
const input = 'hello world';

tmpdir.refresh();

fs.promises.open(file, 'w+').then((handle) => {
let calls = 0;
const {
write: originalWriteFunction,
writev: originalWritevFunction
} = handle;
handle.write = function write() {
calls++;
return Reflect.apply(originalWriteFunction, this, arguments);
};
handle.writev = function writev() {
calls++;
return Reflect.apply(originalWritevFunction, this, arguments);
};
const stream = fs.createWriteStream(null, { fd: handle });

stream.end(input);
stream.on('close', common.mustCall(() => {
assert(calls > 0, 'expected at least one call to fileHandle.write or ' +
'fileHandle.writev, got 0');
}));
}).then(common.mustCall());
23 changes: 0 additions & 23 deletions test/parallel/test-fs-write-stream-file-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,3 @@ fs.promises.open(file, 'w+').then((handle) => {
assert.strictEqual(output, input);
}));
}).then(common.mustCall());

fs.promises.open(file, 'w+').then((handle) => {
let calls = 0;
const {
write: originalWriteFunction,
writev: originalWritevFunction
} = handle;
handle.write = function write() {
calls++;
return Reflect.apply(originalWriteFunction, this, arguments);
};
handle.writev = function writev() {
calls++;
return Reflect.apply(originalWritevFunction, this, arguments);
};
const stream = fs.createWriteStream(null, { fd: handle });

stream.end(input);
stream.on('close', common.mustCall(() => {
assert(calls > 0, 'expected at least one call to fileHandle.write or ' +
'fileHandle.writev, got 0');
}));
}).then(common.mustCall());