mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 14:32:04 +00:00

The test previously created two fs.promises.open calls on the same file with w+ back-to-back, and one of them could fail when checking the contents of that file if the other happened to be opening the file for write. Split them into different tests (with different tmpdir) to avoid the race. PR-URL: https://github.com/nodejs/node/pull/44380 Refs: https://github.com/nodejs/reliability/issues/354 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
22 lines
649 B
JavaScript
22 lines
649 B
JavaScript
'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) => {
|
|
handle.on('close', common.mustCall());
|
|
const stream = fs.createWriteStream(null, { fd: handle });
|
|
|
|
stream.end(input);
|
|
stream.on('close', common.mustCall(() => {
|
|
const output = fs.readFileSync(file, 'utf-8');
|
|
assert.strictEqual(output, input);
|
|
}));
|
|
}).then(common.mustCall());
|