1 var test = require('tap').test
4 // this is like graceful-fs, but in reverse
5 var fs_ = require('fs')
6 var fs = require('../graceful-fs.js')
7 var files = fs.readdirSync(__dirname)
9 // Ok, no more actual file reading!
14 fs_.open = function (path, flags, mode, cb) {
15 process.nextTick(function() {
19 var er = new Error('EMFILE Curses!')
29 fs_.openSync = function (path, flags, mode) {
31 var er = new Error('EMFILE Curses!')
41 fs_.close = function (fd, cb) {
42 process.nextTick(function () {
48 fs_.closeSync = function (fd) {
52 fs_.readdir = function (path, cb) {
53 process.nextTick(function() {
55 var er = new Error('EMFILE Curses!')
61 process.nextTick(function () {
63 cb(null, [__filename, "some-other-file.js"])
69 fs_.readdirSync = function (path) {
71 var er = new Error('EMFILE Curses!')
76 return [__filename, "some-other-file.js"]
81 test('open emfile autoreduce', function (t) {
83 t.equal(fs.MAX_OPEN, 1024)
86 for (var i = 0; i < max; i++) {
87 fs.open(__filename, 'r', next(i))
93 [ [ 0, 60, null, 1024, 4, 12, 1 ],
94 [ 1, 61, null, 1024, 4, 12, 2 ],
95 [ 2, 62, null, 1024, 4, 12, 3 ],
96 [ 3, 63, null, 1024, 4, 12, 4 ],
97 [ 4, 64, null, 1024, 4, 12, 5 ],
98 [ 5, 65, null, 1024, 4, 12, 6 ],
99 [ 6, 66, null, 1024, 4, 12, 7 ],
100 [ 7, 67, null, 6, 4, 5, 1 ],
101 [ 8, 68, null, 6, 4, 5, 2 ],
102 [ 9, 69, null, 6, 4, 5, 3 ],
103 [ 10, 70, null, 6, 4, 5, 4 ],
104 [ 11, 71, null, 6, 4, 5, 5 ] ]
108 function next (i) { return function (er, fd) {
111 actual.push([i, fd, er, fs.MAX_OPEN, fs.MIN_MAX_OPEN, fs._curOpen, fds])
114 t.same(actual, expect)
115 t.ok(fs.MAX_OPEN < limit)
123 test('readdir emfile autoreduce', function (t) {
126 for (var i = 0; i < max; i ++) {
127 fs.readdir(__dirname, next(i))
131 [ [0,[__filename,"some-other-file.js"],null,7,4,7,7],
132 [1,[__filename,"some-other-file.js"],null,7,4,7,6],
133 [2,[__filename,"some-other-file.js"],null,7,4,7,5],
134 [3,[__filename,"some-other-file.js"],null,7,4,7,4],
135 [4,[__filename,"some-other-file.js"],null,7,4,7,3],
136 [5,[__filename,"some-other-file.js"],null,7,4,6,2],
137 [6,[__filename,"some-other-file.js"],null,7,4,5,1],
138 [7,[__filename,"some-other-file.js"],null,7,4,4,0],
139 [8,[__filename,"some-other-file.js"],null,7,4,3,3],
140 [9,[__filename,"some-other-file.js"],null,7,4,2,2],
141 [10,[__filename,"some-other-file.js"],null,7,4,1,1],
142 [11,[__filename,"some-other-file.js"],null,7,4,0,0] ]
146 function next (i) { return function (er, files) {
149 var line = [i, files, er, fs.MAX_OPEN, fs.MIN_MAX_OPEN, fs._curOpen, fds ]
153 t.ok(fs.MAX_OPEN < limit)
154 t.same(actual, expect)