mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 23:23:46 +00:00

The error code, `ECONNRESET`, is observed on linux. This commit adds it as an expected error code. Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: https://github.com/nodejs/node/pull/43961 Refs: https://ci.nodejs.org/job/node-test-commit-linux-containered/nodes=ubuntu1804_sharedlibs_withoutintl_x64/32901/testReport/junit/(root)/test/parallel_test_cluster_concurrent_disconnect/ Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Ref: https://github.com/nodejs/node/issues/32106
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const os = require('os');
|
|
|
|
if (cluster.isPrimary) {
|
|
const workers = [];
|
|
const numCPUs = os.cpus().length;
|
|
let waitOnline = numCPUs;
|
|
for (let i = 0; i < numCPUs; i++) {
|
|
const worker = cluster.fork();
|
|
workers[i] = worker;
|
|
worker.once('online', common.mustCall(() => {
|
|
if (--waitOnline === 0)
|
|
for (const worker of workers)
|
|
if (worker.isConnected())
|
|
worker.send(i % 2 ? 'disconnect' : 'destroy');
|
|
}));
|
|
|
|
// These errors can occur due to the nature of the test, we might be trying
|
|
// to send messages when the worker is disconnecting.
|
|
worker.on('error', (err) => {
|
|
assert.strictEqual(err.syscall, 'write');
|
|
if (common.isOSX) {
|
|
assert(['EPIPE', 'ENOTCONN'].includes(err.code), err);
|
|
} else {
|
|
assert(['EPIPE', 'ECONNRESET'].includes(err.code), err);
|
|
}
|
|
});
|
|
|
|
worker.once('disconnect', common.mustCall(() => {
|
|
for (const worker of workers)
|
|
if (worker.isConnected())
|
|
worker.send('disconnect');
|
|
}));
|
|
|
|
worker.once('exit', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
}));
|
|
}
|
|
} else {
|
|
process.on('message', (msg) => {
|
|
if (cluster.worker.isConnected())
|
|
cluster.worker[msg]();
|
|
});
|
|
}
|