common.js needs to be loaded in all tests so that there is checking for variable leaks and possibly other things. However, it does not need to be assigned to a variable if nothing in common.js is referred to elsewhere in the test. The main tradeoff for this bit of code churn is that it gets the code base most of the way to being able to enable the no-unused-vars rule in eslint. (The non-tooling benefit is that it lessens cognitive load when reading tests as it is an immediate indication that none of the functions or properties in common.js will be used by the test.) PR-URL: https://github.com/nodejs/node/pull/4563 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
|
|
// test variants of pid
|
|
//
|
|
// null: TypeError
|
|
// undefined: TypeError
|
|
//
|
|
// 'SIGTERM': TypeError
|
|
//
|
|
// String(process.pid): TypeError
|
|
//
|
|
// Nan, Infinity, -Infinity: TypeError
|
|
//
|
|
// 0, String(0): our group process
|
|
//
|
|
// process.pid, String(process.pid): ourself
|
|
|
|
assert.throws(function() { process.kill('SIGTERM'); }, TypeError);
|
|
assert.throws(function() { process.kill(null); }, TypeError);
|
|
assert.throws(function() { process.kill(undefined); }, TypeError);
|
|
assert.throws(function() { process.kill(+'not a number'); }, TypeError);
|
|
assert.throws(function() { process.kill(1 / 0); }, TypeError);
|
|
assert.throws(function() { process.kill(-1 / 0); }, TypeError);
|
|
|
|
// Test kill argument processing in valid cases.
|
|
//
|
|
// Monkey patch _kill so that we don't actually send any signals, particularly
|
|
// that we don't kill our process group, or try to actually send ANY signals on
|
|
// windows, which doesn't support them.
|
|
function kill(tryPid, trySig, expectPid, expectSig) {
|
|
var getPid;
|
|
var getSig;
|
|
var origKill = process._kill;
|
|
process._kill = function(pid, sig) {
|
|
getPid = pid;
|
|
getSig = sig;
|
|
|
|
// un-monkey patch process._kill
|
|
process._kill = origKill;
|
|
};
|
|
|
|
process.kill(tryPid, trySig);
|
|
|
|
assert.equal(getPid, expectPid);
|
|
assert.equal(getSig, expectSig);
|
|
}
|
|
|
|
// Note that SIGHUP and SIGTERM map to 1 and 15 respectively, even on Windows
|
|
// (for Windows, libuv maps 1 and 15 to the correct behaviour).
|
|
|
|
kill(0, 'SIGHUP', 0, 1);
|
|
kill(0, undefined, 0, 15);
|
|
kill('0', 'SIGHUP', 0, 1);
|
|
kill('0', undefined, 0, 15);
|
|
|
|
// negative numbers are meaningful on unix
|
|
kill(-1, 'SIGHUP', -1, 1);
|
|
kill(-1, undefined, -1, 15);
|
|
kill('-1', 'SIGHUP', -1, 1);
|
|
kill('-1', undefined, -1, 15);
|
|
|
|
kill(process.pid, 'SIGHUP', process.pid, 1);
|
|
kill(process.pid, undefined, process.pid, 15);
|
|
kill(String(process.pid), 'SIGHUP', process.pid, 1);
|
|
kill(String(process.pid), undefined, process.pid, 15);
|