Skip to content

Commit a213320

Browse files
Sebastian Plesciucevanlucas
authored andcommitted
test: dynamic port in cluster worker disconnect
Remove common.PORT from test-cluster-worker-disconnect-on-error possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: #12457 Ref: #12376 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent ddc3528 commit a213320

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

‎test/parallel/test-cluster-worker-disconnect-on-error.js‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22
constcommon=require('../common');
33
consthttp=require('http');
44
constcluster=require('cluster');
5+
constassert=require('assert');
56

67
cluster.schedulingPolicy=cluster.SCHED_NONE;
78

89
constserver=http.createServer();
910
if(cluster.isMaster){
10-
server.listen(common.PORT);
11-
constworker=cluster.fork();
11+
letworker;
12+
13+
server.listen(0,common.mustCall((error)=>{
14+
assert.ifError(error);
15+
assert(worker);
16+
17+
worker.send({port: server.address().port});
18+
}));
19+
20+
worker=cluster.fork();
1221
worker.on('exit',common.mustCall(()=>{
1322
server.close();
1423
}));
1524
}else{
16-
server.listen(common.PORT);
17-
server.on('error',common.mustCall((e)=>{
18-
cluster.worker.disconnect();
25+
process.on('message',common.mustCall((msg)=>{
26+
assert(msg.port);
27+
28+
server.listen(msg.port);
29+
server.on('error',common.mustCall((e)=>{
30+
cluster.worker.disconnect();
31+
}));
1932
}));
2033
}

0 commit comments

Comments
(0)