Created a test for too many file descriptors on a file

pull/2/head
Louis Chatriot 9 years ago
parent 94cac41acb
commit 61fbf77d18
  1. 13
      test/persistence.test.js
  2. 32
      test_lac/openFds.test.js
  3. 2
      test_lac/openFdsLaunch.sh
  4. 1
      test_lac/openFdsTestFile
  5. 1
      test_lac/openFdsTestFile2

@ -872,6 +872,19 @@ describe('Persistence', function () {
}); });
}); });
it.only("Cannot cause EMFILE errors by opening too many file descriptors", function (done) {
child_process.execFile('test_lac/openFdsLaunch.sh', function (err, stdout, stderr) {
if (err) { return done(err); }
// The subprocess will not output anything to stdout unless part of the test fails
if (stdout.length !== 0) {
return done(stdout);
} else {
return done();
}
});
});
}); // ==== End of 'Prevent dataloss when persisting data' ==== }); // ==== End of 'Prevent dataloss when persisting data' ====

@ -0,0 +1,32 @@
var fs = require('fs')
, child_process = require('child_process')
, async = require('async')
, N = 64 // One file descriptor too many
, i =0
;
function multipleOpen (filename, N, callback) {
async.whilst( function () { return i < N; }
, function (cb) {
fs.open(filename, 'r', function (err, fd) {
i += 1;
return cb(err);
});
}
, callback);
}
async.waterfall([
function (cb) {
multipleOpen('./test_lac/openFdsTestFile', 2 * N + 1, function (err) {
if (!err) { console.log("No error occured while opening a file too many times"); }
return cb();
})
}
, function (cb) {
multipleOpen('./test_lac/openFdsTestFile2', N, function (err) {
if (err) { console.log('An unexpected error occured when opening file not too many times: ' + err); }
})
}
]);

@ -0,0 +1,2 @@
ulimit -n 128
node ./test_lac/openFds.test.js

@ -0,0 +1 @@
Random stuff

@ -0,0 +1 @@
Some other random stuff
Loading…
Cancel
Save