diff --git a/test/persistence.test.js b/test/persistence.test.js index f2e58cb..d00c217 100755 --- a/test/persistence.test.js +++ b/test/persistence.test.js @@ -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' ==== diff --git a/test_lac/openFds.test.js b/test_lac/openFds.test.js new file mode 100644 index 0000000..7ee937f --- /dev/null +++ b/test_lac/openFds.test.js @@ -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); } + }) + } +]); diff --git a/test_lac/openFdsLaunch.sh b/test_lac/openFdsLaunch.sh new file mode 100755 index 0000000..495c8a3 --- /dev/null +++ b/test_lac/openFdsLaunch.sh @@ -0,0 +1,2 @@ +ulimit -n 128 +node ./test_lac/openFds.test.js diff --git a/test_lac/openFdsTestFile b/test_lac/openFdsTestFile new file mode 100644 index 0000000..fcd87b0 --- /dev/null +++ b/test_lac/openFdsTestFile @@ -0,0 +1 @@ +Random stuff diff --git a/test_lac/openFdsTestFile2 b/test_lac/openFdsTestFile2 new file mode 100644 index 0000000..3124b92 --- /dev/null +++ b/test_lac/openFdsTestFile2 @@ -0,0 +1 @@ +Some other random stuff