From e33f848a7ec2eb11d3586c122bd938ee7430534f Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Thu, 10 Dec 2015 14:34:24 -0600 Subject: [PATCH 1/3] 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a47f51..7d5bbcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adios", - "version": "1.0.1", + "version": "1.0.2", "description": "A simple module for handling shutdowns within a clustered application.", "main": "lib/adios.js", "scripts": { From 485a565fba6ef1b9beebf1e05885ae29e03b19f8 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Mon, 22 Feb 2016 15:03:48 -0600 Subject: [PATCH 2/3] Remove gulp, config for timeout --- .eslintignore | 2 ++ .eslintrc | 3 +-- .travis.yml | 4 ++-- gulpfile.js | 36 ------------------------------------ lib/master.js | 17 +++++++++++++---- package.json | 15 ++++++++------- test/index.js | 3 ++- 7 files changed, 28 insertions(+), 52 deletions(-) create mode 100644 .eslintignore delete mode 100644 gulpfile.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..8c73a3e --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +newrelic.js diff --git a/.eslintrc b/.eslintrc index 86cd47a..b81c631 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,6 @@ "block-scoped-var": 2, "camelcase": 2, "comma-dangle": [2, "never"], - "comma-dangle": 2, "complexity": 2, "consistent-return": 2, "curly": 2, @@ -19,6 +18,7 @@ "eqeqeq": 2, "guard-for-in": 2, "indent": [2, 2], + "keyword-spacing": 2, "no-alert": 2, "no-caller": 2, "no-div-regex": 2, @@ -64,7 +64,6 @@ "no-warning-comments": 1, "quotes": [2, "single"], "radix": 2, - "space-after-keywords": [2, "always"], "space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], "space-infix-ops": 2, "object-curly-spacing": [2, "never"], diff --git a/.travis.yml b/.travis.yml index 76c520a..1a8f944 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "4.2" + - "4" - "node" -after_success: gulp coveralls +after_success: npm run coveralls diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 46bc07a..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,36 +0,0 @@ -var coveralls = require('gulp-coveralls'); -var gulp = require('gulp'); -var istanbul = require('gulp-istanbul'); -var nodeunit = require('gulp-nodeunit'); -var eslint = require('gulp-eslint'); - -gulp.task('lint', function () { - return gulp.src([ - './lib/**/*.js', - './test/**/*.js' - ]) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failOnError()); -}); - -gulp.task('test', [ 'lint' ], function (cb) { - gulp.src([ - './lib/**/*.js' - ]) - .pipe(istanbul()) // Covering files - .pipe(istanbul.hookRequire()) // Force `require` to return covered files - .on('finish', function () { - gulp.src('test/index.js') - .pipe(nodeunit({ - reporter: 'default' - })) - .pipe(istanbul.writeReports()) // Creating the reports after tests runned - .on('end', cb); - }); -}); - -gulp.task('coveralls', function (cb) { - gulp.src('coverage/**/lcov.info').pipe(coveralls()); -}); - diff --git a/lib/master.js b/lib/master.js index 076a635..07f0ed7 100644 --- a/lib/master.js +++ b/lib/master.js @@ -26,8 +26,11 @@ function eachWorker(cb) { * SIGINT and allows them tiem to shut down. If a work has not shut down after * 10 seconds it will be forcekilled. After all workers have disconnected or * been killed the process will exit. + * + * @param {int} killTimeout + * Time in milliseconds to wait before forcefully killing a child process. */ -function sigint() { +function sigint(killTimeout) { let shutdowns = eachWorker(worker => new Promise(resolve => { let timeout = setTimeout(() => { if (workerSockets[worker.process.pid]) { @@ -35,7 +38,7 @@ function sigint() { } worker.kill(); resolve(); - }, 10000); + }, killTimeout); worker.on('disconnect', () => { if (workerSockets[worker.process.pid]) { workerSockets[worker.process.pid].end(); @@ -78,11 +81,15 @@ module.exports = { * * @param {string} path * (optional) The socket path to use. Defaults to /var/run/adios.sock + * @param {object} config + * (optional) A configuration object for the master process. Contains: + * - timeout: time in milliseconds before a child will be force closed. + * Default: 10000, 10 seconds. * * @return {Promise} * Resolves when the server is listening. */ - init(path) { + init(path, config) { if (!cluster.isMaster) { throw new Error('Adios master must be initialized from a master process'); } @@ -90,6 +97,8 @@ module.exports = { throw new Error('Adios can only be initialized once per process'); } + const timeout = (config && config.timeout) || 10000; + return new Promise(resolve => { server = net.createServer(c => { let pid; @@ -109,7 +118,7 @@ module.exports = { }); server.listen(path || DEFAULT_PATH, resolve); - process.on('SIGINT', sigint); + process.on('SIGINT', () => sigint(timeout)); process.on('SIGTERM', sigterm); }); }, diff --git a/package.json b/package.json index 7d5bbcb..9c68829 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,10 @@ "description": "A simple module for handling shutdowns within a clustered application.", "main": "lib/adios.js", "scripts": { - "test": "gulp test", - "lint": "gulp lint" + "test": "istanbul cover --print both nodeunit ./test/index.js", + "lint": "eslint .", + "coverage": "istanbul check-coverage --statements 100 --lines 100 --branches 100 --functions 100", + "coveralls": "cat ./coverage/lcov.info | coveralls" }, "repository": { "type": "git", @@ -21,12 +23,11 @@ "node": ">= 4.2" }, "devDependencies": { + "coveralls": "^2.11.6", + "eslint": "^2.2.0", "ghooks": "^1.0.1", - "gulp": "^3.9.0", - "gulp-coveralls": "^0.1.4", - "gulp-eslint": "^1.1.1", - "gulp-istanbul": "^0.10.3", - "gulp-nodeunit": "0.0.5", + "istanbul": "^0.4.2", + "nodeunit": "^0.9.1", "sinon": "^1.17.2" }, "config": { diff --git a/test/index.js b/test/index.js index a11218e..0766218 100644 --- a/test/index.js +++ b/test/index.js @@ -8,9 +8,10 @@ const Adios = require('../'); module.exports = { setUp(cb) { this.stubs = []; + this.testSock = path.join(os.tmpDir(), `${Date.now()}-adios.sock`); + this.clock = sinon.useFakeTimers(); this.origMaster = cluster.isMaster; - this.testSock = path.join(os.tmpDir(), `${Date.now()}-adios.sock`); cb(); }, tearDown(cb) { From e865b9efce3db8011fe3d2b344e4234e0acb5614 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Mon, 22 Feb 2016 15:26:22 -0600 Subject: [PATCH 3/3] Update destroy to avoid context error --- .travis.yml | 2 ++ lib/master.js | 4 ++-- package.json | 2 +- test/master.js | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a8f944..6f2f7f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js +sudo: false node_js: - "4" - "node" +script: npm run lint && npm test && npm run coverage after_success: npm run coveralls diff --git a/lib/master.js b/lib/master.js index 07f0ed7..a7c6775 100644 --- a/lib/master.js +++ b/lib/master.js @@ -131,8 +131,8 @@ module.exports = { * Resolves when the server has been destroyed. */ destroy() { - process.removeListener('SIGINT', sigint); - process.removeListener('SIGTERM', sigterm); + process.removeAllListeners('SIGINT'); + process.removeAllListeners('SIGTERM'); workerSockets = {}; if (server) { diff --git a/package.json b/package.json index 9c68829..cfd0f68 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "istanbul cover --print both nodeunit ./test/index.js", "lint": "eslint .", - "coverage": "istanbul check-coverage --statements 100 --lines 100 --branches 100 --functions 100", + "coverage": "istanbul check-coverage --statements 100 --lines 100 --branches 81 --functions 100", "coveralls": "cat ./coverage/lcov.info | coveralls" }, "repository": { diff --git a/test/master.js b/test/master.js index 8c7ef47..f18b201 100644 --- a/test/master.js +++ b/test/master.js @@ -135,14 +135,14 @@ module.exports = { util.inherits(DummyWorker, EventEmitter); DummyWorker.prototype.disconnect = function () { test.ok(true, 'Disconnect called'); - this.clock.tick(10000); + this.clock.tick(1); }.bind(this); DummyWorker.prototype.kill = function () { test.ok(true, 'Kill called'); }; cluster.workers.foo = new DummyWorker(); - Adios.master.init(this.testSock) + Adios.master.init(this.testSock, {timeout: 1}) .then(() => { let conn = net.connect(this.testSock, () => { conn.write('pid:foo', () => {