mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 22:56:06 +00:00

- Remove assignment of this to variable. - Add common.mustCall() as needed. - Move from var to const. PR-URL: https://github.com/nodejs/node/pull/10547 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
28 lines
890 B
JavaScript
28 lines
890 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const net = require('net');
|
|
|
|
if (cluster.isMaster) {
|
|
// Master opens and binds the socket and shares it with the worker.
|
|
cluster.schedulingPolicy = cluster.SCHED_NONE;
|
|
// Hog the TCP port so that when the worker tries to bind, it'll fail.
|
|
const server = net.createServer(common.fail);
|
|
|
|
server.listen(common.PORT, common.mustCall(() => {
|
|
const worker = cluster.fork();
|
|
worker.on('exit', common.mustCall((exitCode) => {
|
|
assert.strictEqual(exitCode, 0);
|
|
server.close();
|
|
}));
|
|
}));
|
|
} else {
|
|
const s = net.createServer(common.fail);
|
|
s.listen(common.PORT, common.fail.bind(null, 'listen should have failed'));
|
|
s.on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'EADDRINUSE');
|
|
process.disconnect();
|
|
}));
|
|
}
|