Browse Source

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: https://github.com/nodejs/node/pull/3325
Reviewed-By: Joao Reis <reis@janeasystems.com>
v4.x
Johan Bergström 9 years ago
committed by Myles Borins
parent
commit
6b2ef0efac
  1. 23
      test/common.js
  2. 12
      tools/test.py

23
test/common.js

@ -8,6 +8,8 @@ var child_process = require('child_process');
const stream = require('stream'); const stream = require('stream');
const util = require('util'); const util = require('util');
const testRoot = path.resolve(process.env.NODE_TEST_DIR ||
path.dirname(__filename));
exports.testDir = path.dirname(__filename); exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures'); exports.fixturesDir = path.join(exports.testDir, 'fixtures');
@ -69,13 +71,10 @@ exports.refreshTmpDir = function() {
}; };
if (process.env.TEST_THREAD_ID) { if (process.env.TEST_THREAD_ID) {
// Distribute ports in parallel tests exports.PORT += process.env.TEST_THREAD_ID * 100;
if (!process.env.NODE_COMMON_PORT)
exports.PORT += +process.env.TEST_THREAD_ID * 100;
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID; exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
} }
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName); exports.tmpDir = path.join(testRoot, exports.tmpDirName);
var opensslCli = null; var opensslCli = null;
var inFreeBSDJail = null; var inFreeBSDJail = null;
@ -168,21 +167,13 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
if (exports.isWindows) { if (exports.isWindows) {
exports.PIPE = '\\\\.\\pipe\\libuv-test'; exports.PIPE = '\\\\.\\pipe\\libuv-test';
if (process.env.TEST_THREAD_ID) {
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
}
} else { } else {
exports.PIPE = exports.tmpDir + '/test.sock'; exports.PIPE = exports.tmpDir + '/test.sock';
} }
if (process.env.NODE_COMMON_PIPE) {
exports.PIPE = process.env.NODE_COMMON_PIPE;
// Remove manually, the test runner won't do it
// for us like it does for files in test/tmp.
try {
fs.unlinkSync(exports.PIPE);
} catch (e) {
// Ignore.
}
}
if (exports.isWindows) { if (exports.isWindows) {
exports.faketimeCli = false; exports.faketimeCli = false;
} else { } else {

12
tools/test.py

@ -1310,6 +1310,8 @@ def BuildOptions():
result.add_option("-r", "--run", result.add_option("-r", "--run",
help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)", help="Divide the tests in m groups (interleaved) and run tests from group n (--run=n,m with n < m)",
default="") default="")
result.add_option('--temp-dir',
help='Optional path to change directory used for tests', default=False)
return result return result
@ -1541,6 +1543,16 @@ def Main():
for rule in globally_unused_rules: for rule in globally_unused_rules:
print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path]) print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path])
tempdir = os.environ.get('NODE_TEST_DIR') or options.temp_dir
if tempdir:
try:
os.makedirs(tempdir)
os.environ['NODE_TEST_DIR'] = tempdir
except OSError as exception:
if exception.errno != errno.EEXIST:
print "Could not create the temporary directory", options.temp_dir
sys.exit(1)
if options.report: if options.report:
PrintReport(all_cases) PrintReport(all_cases)

Loading…
Cancel
Save