Skip to content

Commit

Permalink
Update tap, touch, make sure all our processes respect SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornstar committed Jul 2, 2020
1 parent ef0c497 commit 62f6689
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 221 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.nyc_output
.vagrant
node_modules
npm-debug.log
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.nyc_output
package-lock.json
test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.2",
"tap": "^12.6.2",
"touch": "^1.0.0"
"tap": "^13.1.2",
"touch": "^3.1.0"
}
}
19 changes: 15 additions & 4 deletions test/fixture/cluster.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
var cluster = require('cluster');

function createWorker() {
function createWorker(i) {
var worker = cluster.fork();
worker.on('message', function (msg) {
console.log('Message from worker:', msg);
console.log('Message from worker', i, ':', msg);
});
worker.on('disconnect', function () {
console.log('Worker disconnected', i);
});
return worker;
}

var workers = [];

if (cluster.isMaster) {
for (var i = 0; i < 2; i += 1) {
console.log('Forking worker', i);
createWorker();
workers.push(createWorker(i));
}
process.on('SIGTERM', function () {
console.log('Master received SIGTERM');
workers.forEach(function (worker) {
worker.disconnect();
});
});
} else {
console.log('Worker started.');
process.send('Hello');
require('./server');
}
4 changes: 4 additions & 0 deletions test/fixture/ipc-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ process.on('message', function (data) {
process.on('exit', function () {
console.log('exit');
});

process.on('SIGTERM', function () {
server.close();
});
1 change: 1 addition & 0 deletions test/fixture/pid.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require('http').createServer().listen(0);
console.log(process.pid);
process.on('SIGTERM', function () { process.exit(); });
2 changes: 2 additions & 0 deletions test/fixture/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ server.listen 8080

console.log 'Server running at http://localhost:8080/'
console.log message

process.on 'SIGTERM', -> server.close()
Loading

0 comments on commit 62f6689

Please sign in to comment.