Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f84a18

Browse filesBrowse files
TrottMylesBorins
authored andcommitted
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. Backport-PR-URL: #23630 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 d4f0366 commit 2f84a18
Copy full SHA for 2f84a18

File tree

Expand file treeCollapse file tree

7 files changed

+29
-72
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+29
-72
lines changed
Open diff view settings
Collapse file

‎test/common/README.md‎

Copy file name to clipboardExpand all lines: test/common/README.md
+2-3Lines changed: 2 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
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

Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const os = require('os');
2929
const { exec, execSync, spawnSync } = require('child_process');
3030
const util = require('util');
3131
const Timer = process.binding('timer_wrap').Timer;
32-
const { fixturesDir } = require('./fixtures');
3332
const tmpdir = require('./tmpdir');
3433
const {
3534
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

Collapse file

‎test/fixtures/create-file.js‎

Copy file name to clipboardExpand all lines: test/fixtures/create-file.js
-29Lines changed: 0 additions & 29 deletions
This file was deleted.
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-error-messages.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tmpdir.refresh();
3131
const nonexistentFile = fixtures.path('non-existent');
3232
const nonexistentDir = fixtures.path('non-existent', 'foo', 'bar');
3333
const existingFile = fixtures.path('exit.js');
34-
const existingFile2 = fixtures.path('create-file.js');
34+
const existingFile2 = fixtures.path('a.js');
3535
const existingDir = tmpdir.path;
3636
const existingDir2 = fixtures.path('keys');
3737
const { COPYFILE_EXCL } = fs.constants;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-chunk-problem.js
+20-23Lines changed: 20 additions & 23 deletions
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
});
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-pipe-file-to-http.js
+2-7Lines changed: 2 additions & 7 deletions
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() {
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-module-loading.js
-1Lines changed: 0 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.