Skip to content

Commit 8561462

Browse files
Trottjasnell
authored andcommittedOct 17, 2018
test: refactor common.ddCommand()
* Remove different paths for Windows and POSIX. * Remove fixtures file. Simply run the command immediately/directly. * Since it is never called with more than one value for kilobytes, eliminate that argument. * Update/simplify tests that use this function. (They no longer need to use child_process to run the command.) * Update documentation. PR-URL: #23411 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: George Adams <george.adams@uk.ibm.com>
1 parent 9d6a1d6 commit 8561462

7 files changed

+29
-72
lines changed
 

‎test/common/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ symlinks
5252
([SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx)).
5353
On non-Windows platforms, this always returns `true`.
5454

55-
### ddCommand(filename, kilobytes)
56-
* return [&lt;Object>]
55+
### ddCommand(filename)
5756

58-
Platform normalizes the `dd` command
57+
Creates a 10 MB file of all null characters.
5958

6059
### disableCrashOnUnhandledRejection()
6160

‎test/common/index.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const assert = require('assert');
2828
const os = require('os');
2929
const { exec, execSync, spawnSync } = require('child_process');
3030
const util = require('util');
31-
const { fixturesDir } = require('./fixtures');
3231
const tmpdir = require('./tmpdir');
3332
const {
3433
bits,
@@ -174,13 +173,10 @@ function childShouldThrowAndAbort() {
174173
});
175174
}
176175

177-
function ddCommand(filename, kilobytes) {
178-
if (isWindows) {
179-
const p = path.resolve(fixturesDir, 'create-file.js');
180-
return `"${process.argv[0]}" "${p}" "${filename}" ${kilobytes * 1024}`;
181-
} else {
182-
return `dd if=/dev/zero of="${filename}" bs=1024 count=${kilobytes}`;
183-
}
176+
function ddCommand(filename) {
177+
const fd = fs.openSync(filename, 'w');
178+
fs.ftruncateSync(fd, 10 * 1024 * 1024);
179+
fs.closeSync(fd);
184180
}
185181

186182

‎test/fixtures/create-file.js

-29
This file was deleted.

‎test/parallel/test-fs-error-messages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tmpdir.refresh();
3232
const nonexistentFile = fixtures.path('non-existent');
3333
const nonexistentDir = fixtures.path('non-existent', 'foo', 'bar');
3434
const existingFile = fixtures.path('exit.js');
35-
const existingFile2 = fixtures.path('create-file.js');
35+
const existingFile2 = fixtures.path('a.js');
3636
const existingDir = tmpdir.path;
3737
const existingDir2 = fixtures.path('keys');
3838
const { COPYFILE_EXCL } = fs.constants;

‎test/parallel/test-http-chunk-problem.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,31 @@ function executeRequest(cb) {
6363

6464
tmpdir.refresh();
6565

66-
const ddcmd = common.ddCommand(filename, 10240);
66+
common.ddCommand(filename);
6767

68-
cp.exec(ddcmd, function(err, stdout, stderr) {
69-
assert.ifError(err);
70-
server = http.createServer(function(req, res) {
71-
res.writeHead(200);
68+
server = http.createServer(function(req, res) {
69+
res.writeHead(200);
7270

73-
// Create the subprocess
74-
const cat = cp.spawn('cat', [filename]);
71+
// Create the subprocess
72+
const cat = cp.spawn('cat', [filename]);
7573

76-
// Stream the data through to the response as binary chunks
77-
cat.stdout.on('data', (data) => {
78-
res.write(data);
79-
});
80-
81-
cat.stdout.on('end', () => res.end());
74+
// Stream the data through to the response as binary chunks
75+
cat.stdout.on('data', (data) => {
76+
res.write(data);
77+
});
8278

83-
// End the response on exit (and log errors)
84-
cat.on('exit', (code) => {
85-
if (code !== 0) {
86-
console.error(`subprocess exited with code ${code}`);
87-
process.exit(1);
88-
}
89-
});
79+
cat.stdout.on('end', () => res.end());
9080

81+
// End the response on exit (and log errors)
82+
cat.on('exit', (code) => {
83+
if (code !== 0) {
84+
console.error(`subprocess exited with code ${code}`);
85+
process.exit(1);
86+
}
9187
});
9288

93-
server.listen(0, () => {
94-
executeRequest(() => server.close());
95-
});
89+
});
90+
91+
server.listen(0, () => {
92+
executeRequest(() => server.close());
9693
});

‎test/parallel/test-pipe-file-to-http.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const assert = require('assert');
2525
const fs = require('fs');
2626
const http = require('http');
2727
const path = require('path');
28-
const cp = require('child_process');
2928

3029
const tmpdir = require('../common/tmpdir');
3130
tmpdir.refresh();
@@ -57,12 +56,8 @@ const server = http.createServer(function(req, res) {
5756
server.listen(0);
5857

5958
server.on('listening', function() {
60-
const cmd = common.ddCommand(filename, 10240);
61-
62-
cp.exec(cmd, function(err) {
63-
assert.ifError(err);
64-
makeRequest();
65-
});
59+
common.ddCommand(filename);
60+
makeRequest();
6661
});
6762

6863
function makeRequest() {

‎test/sequential/test-module-loading.js

-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ try {
251251

252252
assert.deepStrictEqual(children, {
253253
'common/index.js': {
254-
'common/fixtures.js': {},
255254
'common/tmpdir.js': {}
256255
},
257256
'fixtures/not-main-module.js': {},

0 commit comments

Comments
 (0)