xref: /third_party/node/test/parallel/test-cluster-worker-handle-close.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst cluster = require('cluster');
41cb0ef41Sopenharmony_ciconst net = require('net');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (cluster.isPrimary) {
71cb0ef41Sopenharmony_ci  cluster.schedulingPolicy = cluster.SCHED_RR;
81cb0ef41Sopenharmony_ci  cluster.fork();
91cb0ef41Sopenharmony_ci} else {
101cb0ef41Sopenharmony_ci  const server = net.createServer(common.mustNotCall());
111cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
121cb0ef41Sopenharmony_ci    net.connect(server.address().port);
131cb0ef41Sopenharmony_ci  }));
141cb0ef41Sopenharmony_ci  process.prependListener('internalMessage', common.mustCallAtLeast((message, handle) => {
151cb0ef41Sopenharmony_ci    if (message.act !== 'newconn') {
161cb0ef41Sopenharmony_ci      return;
171cb0ef41Sopenharmony_ci    }
181cb0ef41Sopenharmony_ci    // Make the worker drops the connection, see `rr` and `onconnection` in child.js
191cb0ef41Sopenharmony_ci    server.close();
201cb0ef41Sopenharmony_ci    const close = handle.close;
211cb0ef41Sopenharmony_ci    handle.close = common.mustCall(() => {
221cb0ef41Sopenharmony_ci      close.call(handle, common.mustCall(() => {
231cb0ef41Sopenharmony_ci        process.exit();
241cb0ef41Sopenharmony_ci      }));
251cb0ef41Sopenharmony_ci    });
261cb0ef41Sopenharmony_ci  }));
271cb0ef41Sopenharmony_ci}
28

Indexes created Thu Nov 07 10:32:03 CST 2024