• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4if (common.isWindows)
5  common.skip('On Windows named pipes live in their own ' +
6              'filesystem and don\'t have a ~100 byte limit');
7if (!common.isMainThread)
8  common.skip('process.chdir is not available in Workers');
9
10const assert = require('assert');
11const cluster = require('cluster');
12const fs = require('fs');
13const net = require('net');
14const path = require('path');
15
16const tmpdir = require('../common/tmpdir');
17
18// Choose a socket name such that the absolute path would exceed 100 bytes.
19const socketDir = './unix-socket-dir';
20const socketName = 'A'.repeat(101 - socketDir.length);
21
22// Make sure we're not in a weird environment.
23assert.ok(path.resolve(socketDir, socketName).length > 100,
24          'absolute socket path should be longer than 100 bytes');
25
26if (cluster.isMaster) {
27  // Ensure that the worker exits peacefully.
28  tmpdir.refresh();
29  process.chdir(tmpdir.path);
30  fs.mkdirSync(socketDir);
31  cluster.fork().on('exit', common.mustCall((statusCode) => {
32    assert.strictEqual(statusCode, 0);
33
34    assert.ok(!fs.existsSync(path.join(socketDir, socketName)),
35              'Socket should be removed when the worker exits');
36  }));
37} else {
38  process.chdir(socketDir);
39
40  const server = net.createServer(common.mustNotCall());
41
42  server.listen(socketName, common.mustCall(() => {
43    assert.ok(fs.existsSync(socketName), 'Socket created in CWD');
44
45    process.disconnect();
46  }));
47}
48