Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
test: Fix test-fs-read-stream-fd-leak race cond
Browse files Browse the repository at this point in the history
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: nodejs/node#3218
Fixes: nodejs/node#3215
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James Snell <jasnell@gmail.com>>
  • Loading branch information
Junliang Yan authored and mhdawson committed Oct 8, 2015
1 parent 178ac33 commit 8aa589c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/parallel/test-fs-read-stream-fd-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var _fsopen = fs.open;
var _fsclose = fs.close;

var loopCount = 50;
var totalCheck = 50;
var emptyTxt = path.join(common.fixturesDir, 'empty.txt');

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

var i = 0;
var check = 0;

var checkFunction = function() {
if (openCount != 0 && check < totalCheck) {
check++;
setTimeout(checkFunction, 100);
return;
}
assert.equal(0, openCount, 'no leaked file descriptors using ' +
endFn + '() (got ' + openCount + ')');
openCount = 0;
callback && setTimeout(callback, 100);
};

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

if (++i === loopCount) {
clearTimeout(this);
setTimeout(function() {
assert.equal(0, openCount, 'no leaked file descriptors using ' +
endFn + '() (got ' + openCount + ')');
openCount = 0;
callback && setTimeout(callback, 100);
}, 100);
setTimeout(checkFunction, 100);
}
}, 2);
}
Expand Down

0 comments on commit 8aa589c

Please sign in to comment.