From e492f92ec5a89f6cfd3da7fdb9db14c8d2cf9d0a Mon Sep 17 00:00:00 2001 From: Marcus Scott Date: Tue, 16 Oct 2018 14:16:17 +0000 Subject: test: move test-fs-watch-system-limit from sequential to pummel PR-URL: https://github.com/nodejs/node/pull/23692 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/pummel/test-fs-watch-system-limit.js | 67 +++++++++++++++++++++++++++ test/sequential/test-fs-watch-system-limit.js | 67 --------------------------- 2 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 test/pummel/test-fs-watch-system-limit.js delete mode 100644 test/sequential/test-fs-watch-system-limit.js diff --git a/test/pummel/test-fs-watch-system-limit.js b/test/pummel/test-fs-watch-system-limit.js new file mode 100644 index 0000000000..8b9cb62ad0 --- /dev/null +++ b/test/pummel/test-fs-watch-system-limit.js @@ -0,0 +1,67 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const child_process = require('child_process'); +const fs = require('fs'); +const stream = require('stream'); + +if (!common.isLinux) + common.skip('The fs watch limit is OS-dependent'); +if (!common.enoughTestCpu) + common.skip('This test is resource-intensive'); + +try { + // Ensure inotify limit is low enough for the test to actually exercise the + // limit with small enough resources. + const limit = Number( + fs.readFileSync('/proc/sys/fs/inotify/max_user_watches', 'utf8')); + if (limit > 16384) + common.skip('inotify limit is quite large'); +} catch (e) { + if (e.code === 'ENOENT') + common.skip('the inotify /proc subsystem does not exist'); + // Fail on other errors. + throw e; +} + +const processes = []; +const gatherStderr = new stream.PassThrough(); +gatherStderr.setEncoding('utf8'); +gatherStderr.setMaxListeners(Infinity); + +let finished = false; +function spawnProcesses() { + for (let i = 0; i < 10; ++i) { + const proc = child_process.spawn( + process.execPath, + [ '-e', + `process.chdir(${JSON.stringify(__dirname)}); + for (const file of fs.readdirSync('.')) + fs.watch(file, () => {});` + ], { stdio: ['inherit', 'inherit', 'pipe'] }); + proc.stderr.pipe(gatherStderr); + processes.push(proc); + } + + setTimeout(() => { + if (!finished && processes.length < 200) + spawnProcesses(); + }, 100); +} + +spawnProcesses(); + +let accumulated = ''; +gatherStderr.on('data', common.mustCallAtLeast((chunk) => { + accumulated += chunk; + if (accumulated.includes('Error:') && !finished) { + assert( + accumulated.includes('ENOSPC: System limit for number ' + + 'of file watchers reached') || + accumulated.includes('EMFILE: '), + accumulated); + console.log(`done after ${processes.length} processes, cleaning up`); + finished = true; + processes.forEach((proc) => proc.kill()); + } +}, 1)); diff --git a/test/sequential/test-fs-watch-system-limit.js b/test/sequential/test-fs-watch-system-limit.js deleted file mode 100644 index 8b9cb62ad0..0000000000 --- a/test/sequential/test-fs-watch-system-limit.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; -const common = require('../common'); -const assert = require('assert'); -const child_process = require('child_process'); -const fs = require('fs'); -const stream = require('stream'); - -if (!common.isLinux) - common.skip('The fs watch limit is OS-dependent'); -if (!common.enoughTestCpu) - common.skip('This test is resource-intensive'); - -try { - // Ensure inotify limit is low enough for the test to actually exercise the - // limit with small enough resources. - const limit = Number( - fs.readFileSync('/proc/sys/fs/inotify/max_user_watches', 'utf8')); - if (limit > 16384) - common.skip('inotify limit is quite large'); -} catch (e) { - if (e.code === 'ENOENT') - common.skip('the inotify /proc subsystem does not exist'); - // Fail on other errors. - throw e; -} - -const processes = []; -const gatherStderr = new stream.PassThrough(); -gatherStderr.setEncoding('utf8'); -gatherStderr.setMaxListeners(Infinity); - -let finished = false; -function spawnProcesses() { - for (let i = 0; i < 10; ++i) { - const proc = child_process.spawn( - process.execPath, - [ '-e', - `process.chdir(${JSON.stringify(__dirname)}); - for (const file of fs.readdirSync('.')) - fs.watch(file, () => {});` - ], { stdio: ['inherit', 'inherit', 'pipe'] }); - proc.stderr.pipe(gatherStderr); - processes.push(proc); - } - - setTimeout(() => { - if (!finished && processes.length < 200) - spawnProcesses(); - }, 100); -} - -spawnProcesses(); - -let accumulated = ''; -gatherStderr.on('data', common.mustCallAtLeast((chunk) => { - accumulated += chunk; - if (accumulated.includes('Error:') && !finished) { - assert( - accumulated.includes('ENOSPC: System limit for number ' + - 'of file watchers reached') || - accumulated.includes('EMFILE: '), - accumulated); - console.log(`done after ${processes.length} processes, cleaning up`); - finished = true; - processes.forEach((proc) => proc.kill()); - } -}, 1)); -- cgit v1.2.3