Skip to content

Commit d33279d

Browse files
jbergstroemjasnell
authored andcommitted
test: make temp path customizable
In CI we previously passed `NODE_COMMON_PIPE` to the test runner to avoid long filenames. Add an option to the test runner that allows the user to change the temporary directory instead. This also allows us to run test suites in parallel since `NODE_COMMON_PIPE` otherwise would have been used from multiple tests at the same time. PR-URL: #3325 Reviewed-By: Joao Reis <reis@janeasystems.com>
1 parent cfb0945 commit d33279d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

test/common.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var child_process = require('child_process');
88
const stream = require('stream');
99
const util = require('util');
1010

11+
const testRoot = path.resolve(process.env.NODE_TEST_DIR ||
12+
path.dirname(__filename));
1113

1214
exports.testDir = path.dirname(__filename);
1315
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
@@ -69,13 +71,10 @@ exports.refreshTmpDir = function() {
6971
};
7072

7173
if (process.env.TEST_THREAD_ID) {
72-
// Distribute ports in parallel tests
73-
if (!process.env.NODE_COMMON_PORT)
74-
exports.PORT += +process.env.TEST_THREAD_ID * 100;
75-
74+
exports.PORT += process.env.TEST_THREAD_ID * 100;
7675
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
7776
}
78-
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
77+
exports.tmpDir = path.join(testRoot, exports.tmpDirName);
7978

8079
var opensslCli = null;
8180
var inFreeBSDJail = null;
@@ -168,21 +167,13 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
168167

169168
if (exports.isWindows) {
170169
exports.PIPE = '\\\\.\\pipe\\libuv-test';
170+
if (process.env.TEST_THREAD_ID) {
171+
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
172+
}
171173
} else {
172174
exports.PIPE = exports.tmpDir + '/test.sock';
173175
}
174176

175-
if (process.env.NODE_COMMON_PIPE) {
176-
exports.PIPE = process.env.NODE_COMMON_PIPE;
177-
// Remove manually, the test runner won't do it
178-
// for us like it does for files in test/tmp.
179-
try {
180-
fs.unlinkSync(exports.PIPE);
181-
} catch (e) {
182-
// Ignore.
183-
}
184-
}
185-
186177
if (exports.isWindows) {
187178
exports.faketimeCli = false;
188179
} else {

tools/test.py

+12
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ def BuildOptions():
13101310
result.add_option("-r", "--run",
13111311
help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)",
13121312
default="")
1313+
result.add_option('--temp-dir',
1314+
help='Optional path to change directory used for tests', default=False)
13131315
return result
13141316

13151317

@@ -1541,6 +1543,16 @@ def Main():
15411543
for rule in globally_unused_rules:
15421544
print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path])
15431545

1546+
tempdir = os.environ.get('NODE_TEST_DIR') or options.temp_dir
1547+
if tempdir:
1548+
try:
1549+
os.makedirs(tempdir)
1550+
os.environ['NODE_TEST_DIR'] = tempdir
1551+
except OSError as exception:
1552+
if exception.errno != errno.EEXIST:
1553+
print "Could not create the temporary directory", options.temp_dir
1554+
sys.exit(1)
1555+
15441556
if options.report:
15451557
PrintReport(all_cases)
15461558

0 commit comments

Comments
 (0)