|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const child_process = require('child_process'); |
| 5 | +const stream = require('stream'); |
| 6 | + |
| 7 | +if (!common.isLinux) |
| 8 | + common.skip('The fs watch limit is OS-dependent'); |
| 9 | +if (!common.enoughTestCpu) |
| 10 | + common.skip('This test is resource-intensive'); |
| 11 | + |
| 12 | +const processes = []; |
| 13 | +const gatherStderr = new stream.PassThrough(); |
| 14 | +gatherStderr.setEncoding('utf8'); |
| 15 | +gatherStderr.setMaxListeners(Infinity); |
| 16 | + |
| 17 | +let finished = false; |
| 18 | +function spawnProcesses() { |
| 19 | + for (let i = 0; i < 10; ++i) { |
| 20 | + const proc = child_process.spawn( |
| 21 | + process.execPath, |
| 22 | + [ '-e', |
| 23 | + `process.chdir(${JSON.stringify(__dirname)}); |
| 24 | + for (const file of fs.readdirSync('.')) |
| 25 | + fs.watch(file, () => {});` |
| 26 | + ], { stdio: ['inherit', 'inherit', 'pipe'] }); |
| 27 | + proc.stderr.pipe(gatherStderr); |
| 28 | + processes.push(proc); |
| 29 | + } |
| 30 | + |
| 31 | + setTimeout(() => { |
| 32 | + if (!finished && processes.length < 200) |
| 33 | + spawnProcesses(); |
| 34 | + }, 100); |
| 35 | +} |
| 36 | + |
| 37 | +spawnProcesses(); |
| 38 | + |
| 39 | +let accumulated = ''; |
| 40 | +gatherStderr.on('data', common.mustCallAtLeast((chunk) => { |
| 41 | + accumulated += chunk; |
| 42 | + if (accumulated.includes('Error:') && !finished) { |
| 43 | + assert( |
| 44 | + accumulated.includes('ENOSPC: System limit for number ' + |
| 45 | + 'of file watchers reached'), |
| 46 | + accumulated); |
| 47 | + console.log(`done after ${processes.length} processes, cleaning up`); |
| 48 | + finished = true; |
| 49 | + processes.forEach((proc) => proc.kill()); |
| 50 | + } |
| 51 | +}, 1)); |
0 commit comments