Skip to content

Commit 7c85557

Browse files
Junliang Yanjasnell
Junliang Yan
authored andcommitted
test: Fix test-fs-read-stream-fd-leak race cond
Fix intermittent test failure on slower machines. Gives test longer time to complete but checks at regular intervals so that the test only runs longer on slower machines or in the failure case. PR-URL: #3218 Fixes: #3215 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James Snell <[email protected]>>
1 parent 1850879 commit 7c85557

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

test/parallel/test-fs-read-stream-fd-leak.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var _fsopen = fs.open;
1010
var _fsclose = fs.close;
1111

1212
var loopCount = 50;
13+
var totalCheck = 50;
1314
var emptyTxt = path.join(common.fixturesDir, 'empty.txt');
1415

1516
fs.open = function() {
@@ -26,19 +27,27 @@ function testLeak(endFn, callback) {
2627
console.log('testing for leaks from fs.createReadStream().%s()...', endFn);
2728

2829
var i = 0;
30+
var check = 0;
31+
32+
var checkFunction = function() {
33+
if (openCount != 0 && check < totalCheck) {
34+
check++;
35+
setTimeout(checkFunction, 100);
36+
return;
37+
}
38+
assert.equal(0, openCount, 'no leaked file descriptors using ' +
39+
endFn + '() (got ' + openCount + ')');
40+
openCount = 0;
41+
callback && setTimeout(callback, 100);
42+
};
2943

3044
setInterval(function() {
3145
var s = fs.createReadStream(emptyTxt);
3246
s[endFn]();
3347

3448
if (++i === loopCount) {
3549
clearTimeout(this);
36-
setTimeout(function() {
37-
assert.equal(0, openCount, 'no leaked file descriptors using ' +
38-
endFn + '() (got ' + openCount + ')');
39-
openCount = 0;
40-
callback && setTimeout(callback, 100);
41-
}, 100);
50+
setTimeout(checkFunction, 100);
4251
}
4352
}, 2);
4453
}

0 commit comments

Comments
 (0)