summaryrefslogtreecommitdiff
path: root/test/sequential/test-cluster-net-listen-ipv6only-none.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-09-24 23:00:23 -0700
committerRich Trott <rtrott@gmail.com>2019-09-30 18:56:17 -0700
commit1c5a3f0d091ef34b82f89dce4c87b431cab4c3ee (patch)
treeb48452ca30fff4ca1c1bab11251dadff671a82b8 /test/sequential/test-cluster-net-listen-ipv6only-none.js
parent2487f390307b28be8c2d1d137f483900937237eb (diff)
downloadandroid-node-v8-1c5a3f0d091ef34b82f89dce4c87b431cab4c3ee.tar.gz
android-node-v8-1c5a3f0d091ef34b82f89dce4c87b431cab4c3ee.tar.bz2
android-node-v8-1c5a3f0d091ef34b82f89dce4c87b431cab4c3ee.zip
test: fix flaky test-cluster-net-listen-ipv6only-none
test-cluster-net-listen-ipv6only-none was using port `0` for an IPv6-only operation and assuming that the operating system would supply a port that was also available in IPv4. However, CI results seem to indicate that a port can be supplied that is in use by IPv4 but available to IPv6, resulting in the test failing. Use `common.PORT` to avoid this issue. Fixes: https://github.com/nodejs/node/issues/29679 PR-URL: https://github.com/nodejs/node/pull/29681 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'test/sequential/test-cluster-net-listen-ipv6only-none.js')
-rw-r--r--test/sequential/test-cluster-net-listen-ipv6only-none.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/sequential/test-cluster-net-listen-ipv6only-none.js b/test/sequential/test-cluster-net-listen-ipv6only-none.js
new file mode 100644
index 0000000000..d520b7f25c
--- /dev/null
+++ b/test/sequential/test-cluster-net-listen-ipv6only-none.js
@@ -0,0 +1,57 @@
+'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_NONE` schedulingPolicy.
+cluster.schedulingPolicy = cluster.SCHED_NONE;
+const host = '::';
+const WORKER_ACCOUNT = 3;
+
+if (cluster.isMaster) {
+ const workers = new Map();
+
+ const countdown = new Countdown(WORKER_ACCOUNT, () => {
+ // Make sure the `ipv6Only` option works. This is the part of the test that
+ // requires the whole test to use `common.PORT` rather than port `0`. If it
+ // used port `0` instead, then the operating system can supply a port that
+ // is available for the IPv6 interface but in use by the IPv4 interface.
+ // Refs: https://github.com/nodejs/node/issues/29679
+ const server = net.createServer().listen({
+ host: '0.0.0.0',
+ port: common.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) => {
+ assert.strictEqual(workerAddress.addressType, 6);
+ assert.strictEqual(workerAddress.address, host);
+ assert.strictEqual(workerAddress.port, common.PORT);
+ countdown.dec();
+ }));
+
+ workers.set(i, worker);
+ }
+} else {
+ net.createServer().listen({
+ host,
+ port: common.PORT,
+ ipv6Only: true,
+ }, common.mustCall());
+}