From 63e78edc4d51049d65ec06dd0584d095a70bb2f7 Mon Sep 17 00:00:00 2001 From: liusi Date: Tue, 21 Feb 2017 09:57:42 +0800 Subject: [PATCH 1/8] test: test clusters --inspect-brk and --debug-brk This test ensures that flag --inspect-brk and --debug-brk works properly for clusters. --- .../test-cluster-inspector-debug-brk.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/parallel/test-cluster-inspector-debug-brk.js diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js new file mode 100644 index 00000000000000..d9ef5cb77e7b86 --- /dev/null +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -0,0 +1,43 @@ +'use strict'; +// This test ensures that flag --inspect-brk and --debug-brk works properly + +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); + +const script = common.fixturesDir + '/empty.js'; + +function fail() { + assert(0); // `node --debug-brk script.js` should not quit +} + +if (cluster.isMaster) { + + function fork(execArgv) { + cluster.setupMaster({execArgv}); + let worker = cluster.fork(); + + worker.on('exit', fail); + + // give node time to start up the debugger + setTimeout(() => { + worker.removeListener('exit', fail); + worker.kill(); + }, 2000); + + return worker; + } + + let workers = [ + fork([script, '--inspect-brk']), + fork([script, `--inspect-brk=5959`]), + fork([script, '--debug-brk']), + fork([script, `--debug-brk=9230`]) + ]; + + process.on('exit', function() { + workers.map((wk) => { + assert.equal(wk.process.killed, true); + }); + }); +} From e2c86af1d3940ff777f8ebaadff66c4fab2b31a9 Mon Sep 17 00:00:00 2001 From: liusi Date: Tue, 21 Feb 2017 17:15:23 +0800 Subject: [PATCH 2/8] test: test clusters --inspect-brk and --debug-brk This test ensures that flag --inspect-brk and --debug-brk works properly for clusters. --- .../test-cluster-inspector-debug-brk.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index d9ef5cb77e7b86..0fccfdb10db476 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -1,10 +1,12 @@ 'use strict'; +// Flags: --inspect={PORT} // This test ensures that flag --inspect-brk and --debug-brk works properly - const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); +const net = require('net'); +const debuggerPort = common.PORT; const script = common.fixturesDir + '/empty.js'; function fail() { @@ -13,26 +15,29 @@ function fail() { if (cluster.isMaster) { - function fork(execArgv) { - cluster.setupMaster({execArgv}); + function fork(offset, execArgv) { + cluster.setupMaster(execArgv); let worker = cluster.fork(); worker.on('exit', fail); // give node time to start up the debugger - setTimeout(() => { + let socket = net.connect(debuggerPort + offset, () => { + socket.end(); worker.removeListener('exit', fail); worker.kill(); - }, 2000); + }); return worker; } + assert.strictEqual(process.debugPort, debuggerPort); + let workers = [ - fork([script, '--inspect-brk']), - fork([script, `--inspect-brk=5959`]), - fork([script, '--debug-brk']), - fork([script, `--debug-brk=9230`]) + fork(1, [`--inspect-brk`, script]), + fork(2, [`--inspect-brk=${debuggerPort}`, script]), + fork(3, [`--debug-brk`, script]), + fork(4, [`--debug-brk=${debuggerPort}`, script]) ]; process.on('exit', function() { @@ -40,4 +45,4 @@ if (cluster.isMaster) { assert.equal(wk.process.killed, true); }); }); -} +} \ No newline at end of file From c6c73d28daa340bc86d72a129328f00088d01876 Mon Sep 17 00:00:00 2001 From: liusi Date: Tue, 21 Feb 2017 17:24:02 +0800 Subject: [PATCH 3/8] remove unwanted comments --- test/parallel/test-cluster-inspector-debug-brk.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index 0fccfdb10db476..34323e9ffd8f44 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -21,7 +21,6 @@ if (cluster.isMaster) { worker.on('exit', fail); - // give node time to start up the debugger let socket = net.connect(debuggerPort + offset, () => { socket.end(); worker.removeListener('exit', fail); From e7b197597a6f9f3ba16f20a11d89da8850c6a8ef Mon Sep 17 00:00:00 2001 From: liusi Date: Mon, 27 Feb 2017 15:38:59 +0800 Subject: [PATCH 4/8] fix review comments: - wrap callbacks in `common.mustCall`. - check exit code of the cluster worker process instead of checking from main process. - other misc. corrections. --- .../test-cluster-inspector-debug-brk.js | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index 34323e9ffd8f44..4a8b19fa474710 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -9,39 +9,31 @@ const net = require('net'); const debuggerPort = common.PORT; const script = common.fixturesDir + '/empty.js'; -function fail() { - assert(0); // `node --debug-brk script.js` should not quit -} - if (cluster.isMaster) { function fork(offset, execArgv) { cluster.setupMaster(execArgv); let worker = cluster.fork(); - worker.on('exit', fail); + worker.on('exit', common.mustCall((code, signal) => { + assert.strictEqual(code, null); + assert.strictEqual(signal, 'SIGTERM'); + })); - let socket = net.connect(debuggerPort + offset, () => { + let socket = net.connect(debuggerPort + offset, common.mustCall(() => { socket.end(); - worker.removeListener('exit', fail); worker.kill(); - }); - - return worker; + })); } assert.strictEqual(process.debugPort, debuggerPort); - let workers = [ - fork(1, [`--inspect-brk`, script]), - fork(2, [`--inspect-brk=${debuggerPort}`, script]), - fork(3, [`--debug-brk`, script]), - fork(4, [`--debug-brk=${debuggerPort}`, script]) - ]; + fork(1, [`--inspect-brk`, script]); + fork(2, [`--inspect-brk=${debuggerPort}`, script]); + fork(3, [`--debug-brk`, script]); + fork(4, [`--debug-brk=${debuggerPort}`, script]); - process.on('exit', function() { - workers.map((wk) => { - assert.equal(wk.process.killed, true); - }); + process.on('exit', (code, signal) => { + assert.strictEqual(code, 0); }); } \ No newline at end of file From ab8564961fd2e3fbf297c5fc69ca27d59332b6f3 Mon Sep 17 00:00:00 2001 From: liusi Date: Tue, 28 Feb 2017 10:54:23 +0800 Subject: [PATCH 5/8] fix based on review comments --- .../parallel/test-cluster-inspector-debug-brk.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index 4a8b19fa474710..165c9640d2a7e4 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -13,17 +13,19 @@ if (cluster.isMaster) { function fork(offset, execArgv) { cluster.setupMaster(execArgv); - let worker = cluster.fork(); + const worker = cluster.fork(); worker.on('exit', common.mustCall((code, signal) => { assert.strictEqual(code, null); assert.strictEqual(signal, 'SIGTERM'); })); - let socket = net.connect(debuggerPort + offset, common.mustCall(() => { - socket.end(); - worker.kill(); - })); + worker.on('online', common.mustCall(() => { + const socket = net.connect(debuggerPort + offset, common.mustCall(() => { + socket.end(); + worker.kill(); + })); + })); } assert.strictEqual(process.debugPort, debuggerPort); @@ -32,8 +34,4 @@ if (cluster.isMaster) { fork(2, [`--inspect-brk=${debuggerPort}`, script]); fork(3, [`--debug-brk`, script]); fork(4, [`--debug-brk=${debuggerPort}`, script]); - - process.on('exit', (code, signal) => { - assert.strictEqual(code, 0); - }); } \ No newline at end of file From e1ccdcb2cd683a6bce718f567d2567a7833e2be3 Mon Sep 17 00:00:00 2001 From: liusi Date: Thu, 2 Mar 2017 09:22:20 +0800 Subject: [PATCH 6/8] fix linting error --- test/parallel/test-cluster-inspector-debug-brk.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index 165c9640d2a7e4..c0cd46d3237559 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -25,13 +25,13 @@ if (cluster.isMaster) { socket.end(); worker.kill(); })); - })); + })); } - + assert.strictEqual(process.debugPort, debuggerPort); - fork(1, [`--inspect-brk`, script]); + fork(1, ['--inspect-brk', script]); fork(2, [`--inspect-brk=${debuggerPort}`, script]); - fork(3, [`--debug-brk`, script]); + fork(3, ['--debug-brk', script]); fork(4, [`--debug-brk=${debuggerPort}`, script]); } \ No newline at end of file From c39b0782fc160d17514200fb60c3516c43997e3d Mon Sep 17 00:00:00 2001 From: liusi Date: Fri, 3 Mar 2017 15:42:14 +0800 Subject: [PATCH 7/8] fix linting error --- test/parallel/test-cluster-inspector-debug-brk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index c0cd46d3237559..6c068e225cef30 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -34,4 +34,4 @@ if (cluster.isMaster) { fork(2, [`--inspect-brk=${debuggerPort}`, script]); fork(3, ['--debug-brk', script]); fork(4, [`--debug-brk=${debuggerPort}`, script]); -} \ No newline at end of file +} From 9f9a7255397f2cdb26e22e7d91623577353ae27b Mon Sep 17 00:00:00 2001 From: liusi Date: Tue, 14 Mar 2017 12:51:04 +0800 Subject: [PATCH 8/8] fix test failure on CI machines Remove the check of exit code equals null because on some machines the exit code can be 0 --- test/parallel/test-cluster-inspector-debug-brk.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-cluster-inspector-debug-brk.js b/test/parallel/test-cluster-inspector-debug-brk.js index 6c068e225cef30..77246e17a5267e 100644 --- a/test/parallel/test-cluster-inspector-debug-brk.js +++ b/test/parallel/test-cluster-inspector-debug-brk.js @@ -16,7 +16,6 @@ if (cluster.isMaster) { const worker = cluster.fork(); worker.on('exit', common.mustCall((code, signal) => { - assert.strictEqual(code, null); assert.strictEqual(signal, 'SIGTERM'); }));