11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown');
41cb0ef41Sopenharmony_ciconst cluster = require('cluster');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Test an edge case when using `cluster` and `net.Server.listen()` to
81cb0ef41Sopenharmony_ci// the port of `0`.
91cb0ef41Sopenharmony_ciconst kPort = 0;
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cifunction child() {
121cb0ef41Sopenharmony_ci  const kTime = 2;
131cb0ef41Sopenharmony_ci  const countdown = new Countdown(kTime * 2, () => {
141cb0ef41Sopenharmony_ci    process.exit(0);
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci  for (let i = 0; i < kTime; i += 1) {
171cb0ef41Sopenharmony_ci    const server = net.createServer();
181cb0ef41Sopenharmony_ci    server.listen(kPort, common.mustCall(() => {
191cb0ef41Sopenharmony_ci      server.close(countdown.dec());
201cb0ef41Sopenharmony_ci      const server2 = net.createServer();
211cb0ef41Sopenharmony_ci      server2.listen(kPort, common.mustCall(() => {
221cb0ef41Sopenharmony_ci        server2.close(countdown.dec());
231cb0ef41Sopenharmony_ci      }));
241cb0ef41Sopenharmony_ci    }));
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciif (cluster.isMaster)
291cb0ef41Sopenharmony_ci  cluster.fork(__filename);
301cb0ef41Sopenharmony_cielse
311cb0ef41Sopenharmony_ci  child();
32