Skip to content

Commit 46d14fc

Browse files
Trotttargos
authored andcommitted
test: refactor cluster-net-listen-relative-path
Refactor test-cluster-net-listen-relative-path: * Use arrow funcitons for callbacks. * Move skip-test code closer to start of file. * Use assert.ok() where appropriate. * Capitalize and punctuate comments. PR-URL: #21863 Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent f89d194 commit 46d14fc

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

test/parallel/test-cluster-net-listen-relative-path.js

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const cluster = require('cluster');
5-
const net = require('net');
6-
const path = require('path');
7-
const fs = require('fs');
8-
9-
const tmpdir = require('../common/tmpdir');
103

114
if (common.isWindows)
125
common.skip('On Windows named pipes live in their own ' +
136
'filesystem and don\'t have a ~100 byte limit');
147
if (!common.isMainThread)
158
common.skip('process.chdir is not available in Workers');
169

10+
const assert = require('assert');
11+
const cluster = require('cluster');
12+
const fs = require('fs');
13+
const net = require('net');
14+
const path = require('path');
15+
16+
const tmpdir = require('../common/tmpdir');
17+
1718
// Choose a socket name such that the absolute path would exceed 100 bytes.
1819
const socketDir = './unix-socket-dir';
1920
const socketName = 'A'.repeat(100 - socketDir.length - 1);
2021

21-
// Make sure we're not in a weird environment
22-
assert.strictEqual(path.resolve(socketDir, socketName).length > 100, true,
23-
'absolute socket path should be longer than 100 bytes');
22+
// Make sure we're not in a weird environment.
23+
assert.ok(path.resolve(socketDir, socketName).length > 100,
24+
'absolute socket path should be longer than 100 bytes');
2425

2526
if (cluster.isMaster) {
26-
// ensure that the worker exits peacefully
27+
// Ensure that the worker exits peacefully.
2728
tmpdir.refresh();
2829
process.chdir(tmpdir.path);
2930
fs.mkdirSync(socketDir);
30-
cluster.fork().on('exit', common.mustCall(function(statusCode) {
31+
cluster.fork().on('exit', common.mustCall((statusCode) => {
3132
assert.strictEqual(statusCode, 0);
3233

33-
assert.strictEqual(
34-
fs.existsSync(path.join(socketDir, socketName)), false,
35-
'Socket should be removed when the worker exits');
34+
assert.ok(!fs.existsSync(path.join(socketDir, socketName)),
35+
'Socket should be removed when the worker exits');
3636
}));
3737
} else {
3838
process.chdir(socketDir);
3939

4040
const server = net.createServer(common.mustNotCall());
4141

42-
server.listen(socketName, common.mustCall(function() {
43-
assert.strictEqual(
44-
fs.existsSync(socketName), true,
45-
'Socket created in CWD');
42+
server.listen(socketName, common.mustCall(() => {
43+
assert.ok(fs.existsSync(socketName), 'Socket created in CWD');
4644

4745
process.disconnect();
4846
}));

0 commit comments

Comments
 (0)