Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make temp path customizable #3325

Merged
merged 2 commits into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var child_process = require('child_process');
const stream = require('stream');
const util = require('util');

const testRoot = path.resolve(process.env.NODE_TEST_DIR ||
path.dirname(__filename));

exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
Expand Down Expand Up @@ -69,13 +71,10 @@ exports.refreshTmpDir = function() {
};

if (process.env.TEST_THREAD_ID) {
// Distribute ports in parallel tests
if (!process.env.NODE_COMMON_PORT)
exports.PORT += +process.env.TEST_THREAD_ID * 100;

exports.PORT += process.env.TEST_THREAD_ID * 100;
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 inFreeBSDJail = null;
Expand Down Expand Up @@ -168,21 +167,13 @@ Object.defineProperty(exports, 'hasFipsCrypto', {

if (exports.isWindows) {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
if (process.env.TEST_THREAD_ID) {
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
}
} else {
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) {
exports.faketimeCli = false;
} else {
Expand Down
18 changes: 9 additions & 9 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ function test_deep_symlink_mix(callback) {
}

/*
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo
/tmp/node-test-realpath-d1 -> ../node-test-realpath-d2
/tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2
/tmp/node-test-realpath-f1 -> $tmpDir/node-test-realpath-d1/foo
/tmp/node-test-realpath-d1 -> $tmpDir/node-test-realpath-d2
/tmp/node-test-realpath-d2/foo -> $tmpDir/node-test-realpath-f2
/tmp/node-test-realpath-f2
-> /node/test/fixtures/nested-index/one/realpath-c
/node/test/fixtures/nested-index/one/realpath-c
-> /node/test/fixtures/nested-index/two/realpath-c
/node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js
/node/test/fixtures/nested-index/two/realpath-c -> $tmpDir/cycles/root.js
/node/test/fixtures/cycles/root.js (hard)
*/
var entry = tmp('node-test-realpath-f1');
Expand All @@ -289,16 +289,16 @@ function test_deep_symlink_mix(callback) {
fs.mkdirSync(tmp('node-test-realpath-d2'), 0o700);
try {
[
[entry, '../' + common.tmpDirName + '/node-test-realpath-d1/foo'],
[entry, common.tmpDir + '/node-test-realpath-d1/foo'],
[tmp('node-test-realpath-d1'),
'../' + common.tmpDirName + '/node-test-realpath-d2'],
common.tmpDir + '/node-test-realpath-d2'],
[tmp('node-test-realpath-d2/foo'), '../node-test-realpath-f2'],
[tmp('node-test-realpath-f2'), fixturesAbsDir +
'/nested-index/one/realpath-c'],
'/nested-index/one/realpath-c'],
[fixturesAbsDir + '/nested-index/one/realpath-c', fixturesAbsDir +
'/nested-index/two/realpath-c'],
'/nested-index/two/realpath-c'],
[fixturesAbsDir + '/nested-index/two/realpath-c',
'../../../' + common.tmpDirName + '/cycles/root.js']
common.tmpDir + '/cycles/root.js']
].forEach(function(t) {
try { fs.unlinkSync(t[0]); } catch (e) {}
fs.symlinkSync(t[1], t[0]);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-symlink-dir-junction-relative.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var expected_tests = 2;
var linkPath1 = path.join(common.tmpDir, 'junction1');
var linkPath2 = path.join(common.tmpDir, 'junction2');
var linkTarget = path.join(common.fixturesDir);
var linkData = '../fixtures';
var linkData = path.join(common.fixturesDir);

common.refreshTmpDir();

Expand Down Expand Up @@ -42,4 +42,3 @@ function verifyLink(linkPath) {
process.on('exit', function() {
assert.equal(completed, expected_tests);
});

12 changes: 12 additions & 0 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,8 @@ def BuildOptions():
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)",
default="")
result.add_option('--temp-dir',
help='Optional path to change directory used for tests', default=False)
return result


Expand Down Expand Up @@ -1538,6 +1540,16 @@ def Main():
for rule in globally_unused_rules:
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:
PrintReport(all_cases)

Expand Down