Skip to content

Commit a6b8ee1

Browse files
Trottrvagg
authored andcommitted
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: #1877 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 6e4d302 commit a6b8ee1

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

test/common.js

+55
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,59 @@ exports.tmpDirName = 'tmp';
1212
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
1313
exports.isWindows = process.platform === 'win32';
1414

15+
function rimrafSync(p) {
16+
try {
17+
var st = fs.lstatSync(p);
18+
} catch (e) {
19+
if (e.code === 'ENOENT')
20+
return;
21+
}
22+
23+
try {
24+
if (st && st.isDirectory())
25+
rmdirSync(p, null);
26+
else
27+
fs.unlinkSync(p);
28+
} catch (e) {
29+
if (e.code === 'ENOENT')
30+
return;
31+
if (e.code === 'EPERM')
32+
return rmdirSync(p, er);
33+
if (e.code !== 'EISDIR')
34+
throw e;
35+
rmdirSync(p, e);
36+
}
37+
}
38+
39+
function rmdirSync(p, originalEr) {
40+
try {
41+
fs.rmdirSync(p);
42+
} catch (e) {
43+
if (e.code === 'ENOTDIR')
44+
throw originalEr;
45+
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
46+
fs.readdirSync(p).forEach(function(f) {
47+
rimrafSync(path.join(p, f));
48+
});
49+
fs.rmdirSync(p);
50+
}
51+
}
52+
}
53+
54+
function refreshTmpDir() {
55+
if (!process.send) { // Not a child process
56+
try {
57+
rimrafSync(exports.tmpDir);
58+
} catch (e) {
59+
}
60+
61+
try {
62+
fs.mkdirSync(exports.tmpDir);
63+
} catch (e) {
64+
}
65+
}
66+
}
67+
1568
if (process.env.TEST_THREAD_ID) {
1669
// Distribute ports in parallel tests
1770
if (!process.env.NODE_COMMON_PORT)
@@ -21,6 +74,8 @@ if (process.env.TEST_THREAD_ID) {
2174
}
2275
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
2376

77+
refreshTmpDir();
78+
2479
var opensslCli = null;
2580
var inFreeBSDJail = null;
2681
var localhostIPv4 = null;

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var common = require('../common');
21
var assert = require('assert');
32

43
var n = parseInt(process.argv[2]);

test/fixtures/print-chars.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var common = require('../common');
21
var assert = require('assert');
32

43
var n = parseInt(process.argv[2]);

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ if (process.platform === 'darwin') {
3131
watcher.on('change', function(event, filename) {
3232
assert.ok('change' === event || 'rename' === event);
3333

34-
// Ignore stale events generated by mkdir
35-
if (filename === testsubdirName)
34+
// Ignore stale events generated by mkdir and other tests
35+
if (filename !== relativePathOne)
3636
return;
3737

38-
assert.equal(relativePathOne, filename);
39-
4038
watcher.close();
4139
cleanup();
4240
++watchSeenOne;

test/testpy/__init__.py

-30
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import test
2929
import os
3030
import shutil
31-
from shutil import rmtree
3231
from os import mkdir
3332
from glob import glob
3433
from os.path import join, dirname, exists
@@ -50,35 +49,6 @@ def __init__(self, path, file, arch, mode, context, config, additional=[]):
5049
self.tmpdir = join(dirname(self.config.root), 'tmp')
5150
self.additional_flags = additional
5251

53-
def GetTmpDir(self):
54-
return "%s.%d" % (self.tmpdir, self.thread_id)
55-
56-
57-
def AfterRun(self, result):
58-
# delete the whole tmp dir
59-
try:
60-
rmtree(self.GetTmpDir())
61-
except:
62-
pass
63-
# make it again.
64-
try:
65-
mkdir(self.GetTmpDir())
66-
except:
67-
pass
68-
69-
def BeforeRun(self):
70-
# delete the whole tmp dir
71-
try:
72-
rmtree(self.GetTmpDir())
73-
except:
74-
pass
75-
# make it again.
76-
# intermittently fails on win32, so keep trying
77-
while not os.path.exists(self.GetTmpDir()):
78-
try:
79-
mkdir(self.GetTmpDir())
80-
except:
81-
pass
8252

8353
def GetLabel(self):
8454
return "%s %s" % (self.mode, self.GetName())

0 commit comments

Comments
 (0)