node/test/parallel/test-fs-read-stream-fd-leak.js
cjihrig a69ab27ab4 node: rename from io.js to node
This commit replaces instances of io.js with Node.js, based on the
recent convergence. There are some remaining instances of io.js,
related to build and the installer.

Fixes: https://github.com/nodejs/node/issues/2361
PR-URL: https://github.com/nodejs/node/pull/2367
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
2015-08-23 17:59:43 -04:00

49 lines
1.0 KiB
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var openCount = 0;
var _fsopen = fs.open;
var _fsclose = fs.close;
var loopCount = 50;
var emptyTxt = path.join(common.fixturesDir, 'empty.txt');
fs.open = function() {
openCount++;
return _fsopen.apply(null, arguments);
};
fs.close = function() {
openCount--;
return _fsclose.apply(null, arguments);
};
function testLeak(endFn, callback) {
console.log('testing for leaks from fs.createReadStream().%s()...', endFn);
var i = 0;
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);
}
}, 2);
}
testLeak('close', function() {
testLeak('destroy');
});