Skip to content

Commit 7c79490

Browse files
committed
test: only refresh tmpDir for tests that need it
Expose `common.refreshTmpDir()` and only call it for tests that use common.tmpDir or common.PIPE. A positive side effect is the removal of a code smell where child processes were detected by the presence of `.send()`. Now each process can decide for itself if it needs to refresh tmpDir. PR-URL: #1954 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
1 parent 88d7904 commit 7c79490

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+92
-77
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ test/fixtures
44
test/**/node_modules
55
test/parallel/test-fs-non-number-arguments-throw.js
66
test/disabled
7+
test/tmp*/

test/common.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,17 @@ function rmdirSync(p, originalEr) {
5151
}
5252
}
5353

54-
function refreshTmpDir() {
55-
if (!process.send) { // Not a child process
56-
try {
57-
rimrafSync(exports.tmpDir);
58-
} catch (e) {
59-
}
54+
exports.refreshTmpDir = function() {
55+
try {
56+
rimrafSync(exports.tmpDir);
57+
} catch (e) {
58+
}
6059

61-
try {
62-
fs.mkdirSync(exports.tmpDir);
63-
} catch (e) {
64-
}
60+
try {
61+
fs.mkdirSync(exports.tmpDir);
62+
} catch (e) {
6563
}
66-
}
64+
};
6765

6866
if (process.env.TEST_THREAD_ID) {
6967
// Distribute ports in parallel tests
@@ -74,8 +72,6 @@ if (process.env.TEST_THREAD_ID) {
7472
}
7573
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
7674

77-
refreshTmpDir();
78-
7975
var opensslCli = null;
8076
var inFreeBSDJail = null;
8177
var localhostIPv4 = null;

test/fixtures/listen-on-socket-and-exit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var common = require('../common');
44
var net = require('net');
55

6+
common.refreshTmpDir();
7+
68
var server = net.createServer().listen(common.PIPE, function() {
79
console.log('child listening');
810
process.send('listening');

test/parallel/test-child-process-fork-exec-path.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if (process.env.FORK) {
1515
process.exit();
1616
}
1717
else {
18+
common.refreshTmpDir();
1819
try {
1920
fs.unlinkSync(copyPath);
2021
}

test/parallel/test-cluster-http-pipe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var cluster = require('cluster');
1010
var http = require('http');
1111

1212
if (cluster.isMaster) {
13+
common.refreshTmpDir();
1314
var ok = false;
1415
var worker = cluster.fork();
1516
worker.on('message', function(msg) {

test/parallel/test-cwd-enoent-repl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (process.platform === 'sunos' || process.platform === 'win32') {
1111
}
1212

1313
var dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid;
14+
common.refreshTmpDir();
1415
fs.mkdirSync(dirname);
1516
process.chdir(dirname);
1617
fs.rmdirSync(dirname);

test/parallel/test-cwd-enoent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if (process.platform === 'sunos' || process.platform === 'win32') {
1111
}
1212

1313
var dirname = common.tmpDir + '/cwd-does-not-exist-' + process.pid;
14+
common.refreshTmpDir();
1415
fs.mkdirSync(dirname);
1516
process.chdir(dirname);
1617
fs.rmdirSync(dirname);

test/parallel/test-file-write-stream.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var assert = require('assert');
55
var path = require('path');
66
var fs = require('fs');
77
var fn = path.join(common.tmpDir, 'write.txt');
8+
common.refreshTmpDir();
89
var file = fs.createWriteStream(fn, {
910
highWaterMark: 10
1011
});

test/parallel/test-file-write-stream2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function removeTestFile() {
3939
}
4040

4141

42-
removeTestFile();
42+
common.refreshTmpDir();
4343

4444
// drain at 0, return false at 10.
4545
file = fs.createWriteStream(filepath, {

test/parallel/test-file-write-stream3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function removeTestFile() {
3939
}
4040

4141

42-
removeTestFile();
42+
common.refreshTmpDir();
4343

4444

4545
function run_test_1() {

0 commit comments

Comments
 (0)