-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: avoid race in file write stream handle tests
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: #44380 Refs: nodejs/reliability#354 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
- Loading branch information
1 parent
c5413a1
commit 4c33e5d
Showing
2 changed files
with
33 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters