From e28e98b19c920a4773ad973f348fa429b4feeb52 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 2 Jun 2015 20:44:03 -0700 Subject: [PATCH 1/3] 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. --- test/common.js | 57 ++++++++++++++++++++++ test/fixtures/print-chars-from-buffer.js | 1 - test/fixtures/print-chars.js | 1 - test/sequential/test-fs-watch-recursive.js | 6 +-- test/testpy/__init__.py | 30 ------------ 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/test/common.js b/test/common.js index cef17d913eaefa..ddf9265aa73dbe 100644 --- a/test/common.js +++ b/test/common.js @@ -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) @@ -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; diff --git a/test/fixtures/print-chars-from-buffer.js b/test/fixtures/print-chars-from-buffer.js index e3b5647d6ed615..53ca743b06ef0a 100644 --- a/test/fixtures/print-chars-from-buffer.js +++ b/test/fixtures/print-chars-from-buffer.js @@ -1,4 +1,3 @@ -var common = require('../common'); var assert = require('assert'); var n = parseInt(process.argv[2]); diff --git a/test/fixtures/print-chars.js b/test/fixtures/print-chars.js index ec97604921fa48..e2223e20f25508 100644 --- a/test/fixtures/print-chars.js +++ b/test/fixtures/print-chars.js @@ -1,4 +1,3 @@ -var common = require('../common'); var assert = require('assert'); var n = parseInt(process.argv[2]); diff --git a/test/sequential/test-fs-watch-recursive.js b/test/sequential/test-fs-watch-recursive.js index f77b86e436985b..91a2701e1c0830 100644 --- a/test/sequential/test-fs-watch-recursive.js +++ b/test/sequential/test-fs-watch-recursive.js @@ -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; diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index a1b89898fe1e27..5933f8b9b62fc3 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -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 @@ -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()) From fea35733540235c5d88d57a9d682aabc4e4f4068 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 9 Jun 2015 04:46:14 -0700 Subject: [PATCH 2/3] test: refactor to conform to file idioms Function declarations converted to idiomatic style for common.js --- test/common.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/common.js b/test/common.js index ddf9265aa73dbe..30eb2bcfb908d1 100644 --- a/test/common.js +++ b/test/common.js @@ -12,7 +12,7 @@ exports.tmpDirName = 'tmp'; exports.PORT = +process.env.NODE_COMMON_PORT || 12346; exports.isWindows = process.platform === 'win32'; -var rimrafSync = function(p) { +function rimrafSync(p) { try { var st = fs.lstatSync(p); } catch (e) { @@ -34,9 +34,9 @@ var rimrafSync = function(p) { throw e; rmdirSync(p, e); } -}; +} -var rmdirSync = function(p, originalEr) { +function rmdirSync(p, originalEr) { try { fs.rmdirSync(p); } catch (e) { @@ -51,9 +51,9 @@ var rmdirSync = function(p, originalEr) { fs.rmdirSync(p); } } -}; +} -var refreshTmpDir = function() { +function refreshTmpDir() { if (!process.send) { // Not a child process try { rimrafSync(exports.tmpDir); @@ -65,7 +65,7 @@ var refreshTmpDir = function() { } catch (e) { } } -}; +} if (process.env.TEST_THREAD_ID) { // Distribute ports in parallel tests From b5acb48d791be397c19b954e4ce6e3c79b13dcc4 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 10 Jun 2015 10:02:01 -0700 Subject: [PATCH 3/3] test: remove no-op --- test/common.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/common.js b/test/common.js index 30eb2bcfb908d1..e88893cd1e8768 100644 --- a/test/common.js +++ b/test/common.js @@ -40,8 +40,6 @@ function rmdirSync(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') {