summaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2019-02-25 09:35:09 -0500
committerGireesh Punathil <gpunathi@in.ibm.com>2019-02-28 10:06:42 +0530
commit4a3928e125bb1ab7242e8134f911b6c71551bd75 (patch)
treed3fcd70db0d4ebb069a61ea1c557079d0a1d0c8a /test/sequential
parent17b4949a84106d70749106985f6d606004acf25a (diff)
downloadandroid-node-v8-4a3928e125bb1ab7242e8134f911b6c71551bd75.tar.gz
android-node-v8-4a3928e125bb1ab7242e8134f911b6c71551bd75.tar.bz2
android-node-v8-4a3928e125bb1ab7242e8134f911b6c71551bd75.zip
test: eliminate port collision
In test test-cluster-net-listen-ipv6only-rr, the cluster member that listens to `any` port actually has the potential to `grab` any port from the environment which when passed onto the master causes collision when it tries to listen on. Moving the test to sequential alone is not sufficient as the cluster member can in theory catch on to the admin ports on the host. Assigning static port alone is also not sufficient, as it can interfere with other running tests in the parallel category which would be mostly running with `port: any` fashion. So move to sequential, and use a static port. Fixes: https://github.com/nodejs/node/issues/25813 PR-URL: https://github.com/nodejs/node/pull/26298 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-cluster-net-listen-ipv6only-rr.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/sequential/test-cluster-net-listen-ipv6only-rr.js b/test/sequential/test-cluster-net-listen-ipv6only-rr.js
new file mode 100644
index 0000000000..a42be88ddf
--- /dev/null
+++ b/test/sequential/test-cluster-net-listen-ipv6only-rr.js
@@ -0,0 +1,61 @@
+'use strict';
+
+const common = require('../common');
+if (!common.hasIPv6)
+ common.skip('no IPv6 support');
+
+const assert = require('assert');
+const cluster = require('cluster');
+const net = require('net');
+const Countdown = require('../common/countdown');
+
+// This test ensures that the `ipv6Only` option in `net.Server.listen()`
+// works as expected when we use cluster with `SCHED_RR` schedulingPolicy.
+cluster.schedulingPolicy = cluster.SCHED_RR;
+const host = '::';
+const WORKER_ACCOUNT = 3;
+
+if (cluster.isMaster) {
+ const workers = new Map();
+ let address;
+
+ const countdown = new Countdown(WORKER_ACCOUNT, () => {
+ // Make sure the `ipv6Only` option works.
+ const server = net.createServer().listen({
+ host: '0.0.0.0',
+ port: address.port,
+ }, common.mustCall(() => {
+ // Exit.
+ server.close();
+ workers.forEach((worker) => {
+ worker.disconnect();
+ });
+ }));
+ });
+
+ for (let i = 0; i < WORKER_ACCOUNT; i += 1) {
+ const worker = cluster.fork().on('exit', common.mustCall((statusCode) => {
+ assert.strictEqual(statusCode, 0);
+ })).on('listening', common.mustCall((workerAddress) => {
+ if (!address) {
+ address = workerAddress;
+ } else {
+ assert.deepStrictEqual(workerAddress, address);
+ }
+ countdown.dec();
+ }));
+
+ workers.set(i, worker);
+ }
+} else {
+ // As the cluster member has the potential to grab any port
+ // from the environment, this can cause collision when master
+ // obtains the port from cluster member and tries to listen on.
+ // So move this to sequential, and provide a static port.
+ // Refs: https://github.com/nodejs/node/issues/25813
+ net.createServer().listen({
+ host: host,
+ port: common.PORT,
+ ipv6Only: true,
+ }, common.mustCall());
+}