test: dynamic port in cluster eaddrinuse
Removed common.PORT from test-cluster-eaddrinuse to eliminate the possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: https://github.com/nodejs/node/pull/12547 Ref: https://github.com/nodejs/node/issues/12376 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
ee8183ed85
commit
d06a6a81a5
@ -30,11 +30,12 @@ const fork = require('child_process').fork;
|
|||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
const id = '' + process.argv[2];
|
const id = '' + process.argv[2];
|
||||||
|
const port = '' + process.argv[3];
|
||||||
|
|
||||||
if (id === 'undefined') {
|
if (id === 'undefined') {
|
||||||
const server = net.createServer(common.mustNotCall());
|
const server = net.createServer(common.mustNotCall());
|
||||||
server.listen(common.PORT, function() {
|
server.listen(0, function() {
|
||||||
const worker = fork(__filename, ['worker']);
|
const worker = fork(__filename, ['worker', server.address().port]);
|
||||||
worker.on('message', function(msg) {
|
worker.on('message', function(msg) {
|
||||||
if (msg !== 'stop-listening') return;
|
if (msg !== 'stop-listening') return;
|
||||||
server.close(function() {
|
server.close(function() {
|
||||||
@ -44,14 +45,14 @@ if (id === 'undefined') {
|
|||||||
});
|
});
|
||||||
} else if (id === 'worker') {
|
} else if (id === 'worker') {
|
||||||
let server = net.createServer(common.mustNotCall());
|
let server = net.createServer(common.mustNotCall());
|
||||||
server.listen(common.PORT, common.mustNotCall());
|
server.listen(port, common.mustNotCall());
|
||||||
server.on('error', common.mustCall(function(e) {
|
server.on('error', common.mustCall(function(e) {
|
||||||
assert(e.code, 'EADDRINUSE');
|
assert(e.code, 'EADDRINUSE');
|
||||||
process.send('stop-listening');
|
process.send('stop-listening');
|
||||||
process.once('message', function(msg) {
|
process.once('message', function(msg) {
|
||||||
if (msg !== 'stopped-listening') return;
|
if (msg !== 'stopped-listening') return;
|
||||||
server = net.createServer(common.mustNotCall());
|
server = net.createServer(common.mustNotCall());
|
||||||
server.listen(common.PORT, common.mustCall(function() {
|
server.listen(port, common.mustCall(function() {
|
||||||
server.close();
|
server.close();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user