summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlaino <lain@volafile.io>2018-01-08 21:05:33 +0100
committerJoyee Cheung <joyeec9h3@gmail.com>2018-01-17 11:55:49 +0800
commit4e2e7d11e16d185a088aec77d1adc7bb4b606806 (patch)
tree7997d0f058bc84ddc9cef0af49a815e543cf0471 /test
parentf878f9414eb6c7ef1d166404ae43444826706db8 (diff)
downloadandroid-node-v8-4e2e7d11e16d185a088aec77d1adc7bb4b606806.tar.gz
android-node-v8-4e2e7d11e16d185a088aec77d1adc7bb4b606806.tar.bz2
android-node-v8-4e2e7d11e16d185a088aec77d1adc7bb4b606806.zip
cluster: resolve relative unix socket paths
Relative unix sockets paths were previously interpreted relative to the master's CWD, which was inconsistent with non-cluster behavior. A test case has been added as well. PR-URL: https://github.com/nodejs/node/pull/16749 Fixes: https://github.com/nodejs/node/issues/16387 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-cluster-net-listen-relative-path.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-cluster-net-listen-relative-path.js b/test/parallel/test-cluster-net-listen-relative-path.js
new file mode 100644
index 0000000000..0fcc6a0dca
--- /dev/null
+++ b/test/parallel/test-cluster-net-listen-relative-path.js
@@ -0,0 +1,44 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const cluster = require('cluster');
+const net = require('net');
+const path = require('path');
+const fs = require('fs');
+
+if (common.isWindows)
+ common.skip('On Windows named pipes live in their own ' +
+ 'filesystem and don\'t have a ~100 byte limit');
+
+// Choose a socket name such that the absolute path would exceed 100 bytes.
+const socketDir = './unix-socket-dir';
+const socketName = 'A'.repeat(100 - socketDir.length - 1);
+
+// Make sure we're not in a weird environment
+assert.strictEqual(path.resolve(socketDir, socketName).length > 100, true,
+ 'absolute socket path should be longer than 100 bytes');
+
+if (cluster.isMaster) {
+ // ensure that the worker exits peacefully
+ process.chdir(common.tmpDir);
+ fs.mkdirSync(socketDir);
+ cluster.fork().on('exit', common.mustCall(function(statusCode) {
+ assert.strictEqual(statusCode, 0);
+
+ assert.strictEqual(
+ fs.existsSync(path.join(socketDir, socketName)), false,
+ 'Socket should be removed when the worker exits');
+ }));
+} else {
+ process.chdir(socketDir);
+
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(socketName, common.mustCall(function() {
+ assert.strictEqual(
+ fs.existsSync(socketName), true,
+ 'Socket created in CWD');
+
+ process.disconnect();
+ }));
+}