test: refactor test-cluster-send-handle-twice.js
- `var` --> `const` as applicable - `assert.equal` --> `assert.strictEqual` - `assert(false, ..)` --> `common.fail()` - `common.mustCall` for functions that need to be called exactly once - modified an `assert(!signal, 'Worker exited by a signal');` call to `assert.strictEqual(signal, null);` call as that made more sense PR-URL: https://github.com/nodejs/node/pull/10049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b00f8ad13a
commit
7e7062cdca
@ -1,36 +1,36 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// Testing to send an handle twice to the parent process.
|
// Testing to send an handle twice to the parent process.
|
||||||
|
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
var net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
var workers = {
|
const workers = {
|
||||||
toStart: 1
|
toStart: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
for (var i = 0; i < workers.toStart; ++i) {
|
for (let i = 0; i < workers.toStart; ++i) {
|
||||||
var worker = cluster.fork();
|
const worker = cluster.fork();
|
||||||
worker.on('exit', function(code, signal) {
|
worker.on('exit', common.mustCall(function(code, signal) {
|
||||||
assert.strictEqual(code, 0, 'Worker exited with an error code');
|
assert.strictEqual(code, 0, 'Worker exited with an error code');
|
||||||
assert(!signal, 'Worker exited by a signal');
|
assert.strictEqual(signal, null, 'Worker exited by a signal');
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var server = net.createServer(function(socket) {
|
const server = net.createServer(function(socket) {
|
||||||
process.send('send-handle-1', socket);
|
process.send('send-handle-1', socket);
|
||||||
process.send('send-handle-2', socket);
|
process.send('send-handle-2', socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function() {
|
||||||
var client = net.connect({ host: 'localhost', port: common.PORT });
|
const client = net.connect({ host: 'localhost', port: common.PORT });
|
||||||
client.on('close', function() { cluster.worker.disconnect(); });
|
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
|
||||||
setTimeout(function() { client.end(); }, 50);
|
setTimeout(function() { client.end(); }, 50);
|
||||||
}).on('error', function(e) {
|
}).on('error', function(e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
assert(false, 'server.listen failed');
|
common.fail('server.listen failed');
|
||||||
cluster.worker.disconnect();
|
cluster.worker.disconnect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user