react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / node_modules / commoner / node_modules / graceful-fs / test / max-open.js
81169 viewsvar test = require('tap').test1var fs = require('../')23test('open lots of stuff', function (t) {4// Get around EBADF from libuv by making sure that stderr is opened5// Otherwise Darwin will refuse to give us a FD for stderr!6process.stderr.write('')78// How many parallel open()'s to do9var n = 102410var opens = 011var fds = []12var going = true13var closing = false14var doneCalled = 01516for (var i = 0; i < n; i++) {17go()18}1920function go() {21opens++22fs.open(__filename, 'r', function (er, fd) {23if (er) throw er24fds.push(fd)25if (going) go()26})27}2829// should hit ulimit pretty fast30setTimeout(function () {31going = false32t.equal(opens - fds.length, n)33done()34}, 100)353637function done () {38if (closing) return39doneCalled++4041if (fds.length === 0) {42//console.error('done called %d times', doneCalled)43// First because of the timeout44// Then to close the fd's opened afterwards45// Then this time, to complete.46// Might take multiple passes, depending on CPU speed47// and ulimit, but at least 3 in every case.48t.ok(doneCalled >= 3)49return t.end()50}5152closing = true53setTimeout(function () {54// console.error('do closing again')55closing = false56done()57}, 100)5859// console.error('closing time')60var closes = fds.slice(0)61fds.length = 062closes.forEach(function (fd) {63fs.close(fd, function (er) {64if (er) throw er65})66})67}68})697071