test: fix flaky test-fs-write

PR-URL: https://github.com/nodejs/node/pull/18374
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Joyee Cheung 2018-01-25 23:01:01 +08:00
parent eb34278dcc
commit 94e36f1f31
No known key found for this signature in database
GPG Key ID: F586868AAD831D0C

View File

@ -34,6 +34,8 @@ const constants = fs.constants;
/* eslint-disable no-undef */ /* eslint-disable no-undef */
common.allowGlobals(externalizeString, isOneByteString, x); common.allowGlobals(externalizeString, isOneByteString, x);
common.refreshTmpDir();
{ {
const expected = 'ümlaut eins'; // Must be a unique string. const expected = 'ümlaut eins'; // Must be a unique string.
externalizeString(expected); externalizeString(expected);
@ -74,8 +76,6 @@ common.allowGlobals(externalizeString, isOneByteString, x);
assert.strictEqual(expected, fs.readFileSync(fn, 'utf8')); assert.strictEqual(expected, fs.readFileSync(fn, 'utf8'));
} }
common.refreshTmpDir();
fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
assert.ifError(err); assert.ifError(err);
@ -91,10 +91,10 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
const written = common.mustCall(function(err, written) { const written = common.mustCall(function(err, written) {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(0, written); assert.strictEqual(0, written);
fs.write(fd, expected, 0, 'utf8', done);
}); });
fs.write(fd, '', 0, 'utf8', written); fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
})); }));
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC; const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
@ -113,10 +113,10 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
const written = common.mustCall(function(err, written) { const written = common.mustCall(function(err, written) {
assert.ifError(err); assert.ifError(err);
assert.strictEqual(0, written); assert.strictEqual(0, written);
fs.write(fd, expected, 0, 'utf8', done);
}); });
fs.write(fd, '', 0, 'utf8', written); fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
})); }));
fs.open(fn3, 'w', 0o644, common.mustCall(function(err, fd) { fs.open(fn3, 'w', 0o644, common.mustCall(function(err, fd) {