Skip to content

Commit 62f6689

Browse files
committed
Update tap, touch, make sure all our processes respect SIGTERM
1 parent ef0c497 commit 62f6689

12 files changed

Lines changed: 268 additions & 221 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
.nyc_output
23
.vagrant
34
node_modules
45
npm-debug.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.nyc_output
12
package-lock.json
23
test

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"eslint": "^5.16.0",
4444
"eslint-config-airbnb-base": "^13.1.0",
4545
"eslint-plugin-import": "^2.17.2",
46-
"tap": "^12.6.2",
47-
"touch": "^1.0.0"
46+
"tap": "^13.1.2",
47+
"touch": "^3.1.0"
4848
}
4949
}

test/fixture/cluster.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
var cluster = require('cluster');
22

3-
function createWorker() {
3+
function createWorker(i) {
44
var worker = cluster.fork();
55
worker.on('message', function (msg) {
6-
console.log('Message from worker:', msg);
6+
console.log('Message from worker', i, ':', msg);
77
});
8+
worker.on('disconnect', function () {
9+
console.log('Worker disconnected', i);
10+
});
11+
return worker;
812
}
913

14+
var workers = [];
15+
1016
if (cluster.isMaster) {
1117
for (var i = 0; i < 2; i += 1) {
1218
console.log('Forking worker', i);
13-
createWorker();
19+
workers.push(createWorker(i));
1420
}
21+
process.on('SIGTERM', function () {
22+
console.log('Master received SIGTERM');
23+
workers.forEach(function (worker) {
24+
worker.disconnect();
25+
});
26+
});
1527
} else {
16-
console.log('Worker started.');
1728
process.send('Hello');
1829
require('./server');
1930
}

test/fixture/ipc-server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ process.on('message', function (data) {
2424
process.on('exit', function () {
2525
console.log('exit');
2626
});
27+
28+
process.on('SIGTERM', function () {
29+
server.close();
30+
});

test/fixture/pid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
require('http').createServer().listen(0);
22
console.log(process.pid);
3+
process.on('SIGTERM', function () { process.exit(); });

test/fixture/server.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ server.listen 8080
1212

1313
console.log 'Server running at http://localhost:8080/'
1414
console.log message
15+
16+
process.on 'SIGTERM', -> server.close()

0 commit comments

Comments
 (0)