Skip to content

Commit

Permalink
test: create temp dir in common.js
Browse files Browse the repository at this point in the history
Move creation of temporary directories for tests
out of the Python harness and into common.js. This
allows all tests to be run reliably outside of the
Python wrapper.
  • Loading branch information
Trott committed Jun 9, 2015
1 parent 38d1afc commit e28e98b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 36 deletions.
57 changes: 57 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,61 @@ exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
exports.isWindows = process.platform === 'win32';

var rimrafSync = function(p) {
try {
var st = fs.lstatSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
}

try {
if (st && st.isDirectory())
rmdirSync(p, null);
else
fs.unlinkSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
if (e.code === 'EPERM')
return rmdirSync(p, er);
if (e.code !== 'EISDIR')
throw e;
rmdirSync(p, e);
}
};

var rmdirSync = function(p, originalEr) {
try {
fs.rmdirSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
if (e.code === 'ENOTDIR')
throw originalEr;
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
fs.readdirSync(p).forEach(function(f) {
rimrafSync(path.join(p, f));
});
fs.rmdirSync(p);
}
}
};

var refreshTmpDir = function() {
if (!process.send) { // Not a child process
try {
rimrafSync(exports.tmpDir);
} catch (e) {
}

try {
fs.mkdirSync(exports.tmpDir);
} catch (e) {
}
}
};

if (process.env.TEST_THREAD_ID) {
// Distribute ports in parallel tests
if (!process.env.NODE_COMMON_PORT)
Expand All @@ -21,6 +76,8 @@ if (process.env.TEST_THREAD_ID) {
}
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);

refreshTmpDir();

var opensslCli = null;
var inFreeBSDJail = null;
var localhostIPv4 = null;
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/print-chars-from-buffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var common = require('../common');
var assert = require('assert');

var n = parseInt(process.argv[2]);
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/print-chars.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var common = require('../common');
var assert = require('assert');

var n = parseInt(process.argv[2]);
Expand Down
6 changes: 2 additions & 4 deletions test/sequential/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ if (process.platform === 'darwin') {
watcher.on('change', function(event, filename) {
assert.ok('change' === event || 'rename' === event);

// Ignore stale events generated by mkdir
if (filename === testsubdirName)
// Ignore stale events generated by mkdir and other tests
if (filename !== relativePathOne)
return;

assert.equal(relativePathOne, filename);

watcher.close();
cleanup();
++watchSeenOne;
Expand Down
30 changes: 0 additions & 30 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import test
import os
import shutil
from shutil import rmtree
from os import mkdir
from glob import glob
from os.path import join, dirname, exists
Expand All @@ -50,35 +49,6 @@ def __init__(self, path, file, arch, mode, context, config, additional=[]):
self.tmpdir = join(dirname(self.config.root), 'tmp')
self.additional_flags = additional

def GetTmpDir(self):
return "%s.%d" % (self.tmpdir, self.thread_id)


def AfterRun(self, result):
# delete the whole tmp dir
try:
rmtree(self.GetTmpDir())
except:
pass
# make it again.
try:
mkdir(self.GetTmpDir())
except:
pass

def BeforeRun(self):
# delete the whole tmp dir
try:
rmtree(self.GetTmpDir())
except:
pass
# make it again.
# intermittently fails on win32, so keep trying
while not os.path.exists(self.GetTmpDir()):
try:
mkdir(self.GetTmpDir())
except:
pass

def GetLabel(self):
return "%s %s" % (self.mode, self.GetName())
Expand Down

0 comments on commit e28e98b

Please sign in to comment.