Browse Source

test: create temp dir in common.js

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.

PR-URL: https://github.com/nodejs/io.js/pull/1877
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v2.3.1-release
Rich Trott 10 years ago
committed by Rod Vagg
parent
commit
a6b8ee19b8
  1. 55
      test/common.js
  2. 1
      test/fixtures/print-chars-from-buffer.js
  3. 1
      test/fixtures/print-chars.js
  4. 6
      test/sequential/test-fs-watch-recursive.js
  5. 30
      test/testpy/__init__.py

55
test/common.js

@ -12,6 +12,59 @@ exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346; exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
exports.isWindows = process.platform === 'win32'; exports.isWindows = process.platform === 'win32';
function rimrafSync(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);
}
}
function rmdirSync(p, originalEr) {
try {
fs.rmdirSync(p);
} catch (e) {
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);
}
}
}
function refreshTmpDir() {
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) { if (process.env.TEST_THREAD_ID) {
// Distribute ports in parallel tests // Distribute ports in parallel tests
if (!process.env.NODE_COMMON_PORT) if (!process.env.NODE_COMMON_PORT)
@ -21,6 +74,8 @@ if (process.env.TEST_THREAD_ID) {
} }
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName); exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
refreshTmpDir();
var opensslCli = null; var opensslCli = null;
var inFreeBSDJail = null; var inFreeBSDJail = null;
var localhostIPv4 = null; var localhostIPv4 = null;

1
test/fixtures/print-chars-from-buffer.js

@ -1,4 +1,3 @@
var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);

1
test/fixtures/print-chars.js

@ -1,4 +1,3 @@
var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var n = parseInt(process.argv[2]); var n = parseInt(process.argv[2]);

6
test/sequential/test-fs-watch-recursive.js

@ -31,12 +31,10 @@ if (process.platform === 'darwin') {
watcher.on('change', function(event, filename) { watcher.on('change', function(event, filename) {
assert.ok('change' === event || 'rename' === event); assert.ok('change' === event || 'rename' === event);
// Ignore stale events generated by mkdir // Ignore stale events generated by mkdir and other tests
if (filename === testsubdirName) if (filename !== relativePathOne)
return; return;
assert.equal(relativePathOne, filename);
watcher.close(); watcher.close();
cleanup(); cleanup();
++watchSeenOne; ++watchSeenOne;

30
test/testpy/__init__.py

@ -28,7 +28,6 @@
import test import test
import os import os
import shutil import shutil
from shutil import rmtree
from os import mkdir from os import mkdir
from glob import glob from glob import glob
from os.path import join, dirname, exists from os.path import join, dirname, exists
@ -50,35 +49,6 @@ class SimpleTestCase(test.TestCase):
self.tmpdir = join(dirname(self.config.root), 'tmp') self.tmpdir = join(dirname(self.config.root), 'tmp')
self.additional_flags = additional 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): def GetLabel(self):
return "%s %s" % (self.mode, self.GetName()) return "%s %s" % (self.mode, self.GetName())

Loading…
Cancel
Save