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 <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent f89d194 commit 46d14fc

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
11
'use strict';
22
constcommon=require('../common');
3-
constassert=require('assert');
4-
constcluster=require('cluster');
5-
constnet=require('net');
6-
constpath=require('path');
7-
constfs=require('fs');
8-
9-
consttmpdir=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+
constassert=require('assert');
11+
constcluster=require('cluster');
12+
constfs=require('fs');
13+
constnet=require('net');
14+
constpath=require('path');
15+
16+
consttmpdir=require('../common/tmpdir');
17+
1718
// Choose a socket name such that the absolute path would exceed 100 bytes.
1819
constsocketDir='./unix-socket-dir';
1920
constsocketName='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
constserver=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)