-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: create temp dir in common.js #1877
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,61 @@ exports.tmpDirName = 'tmp'; | |
exports.PORT = +process.env.NODE_COMMON_PORT || 12346; | ||
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 === '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); | ||
} | ||
} | ||
} | ||
|
||
function refreshTmpDir() { | ||
if (!process.send) { // Not a child process | ||
try { | ||
rimrafSync(exports.tmpDir); | ||
} catch (e) { | ||
} | ||
|
||
try { | ||
fs.mkdirSync(exports.tmpDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd rather this one be unguarded, if the mkdir fails it should fail the test I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but I was trying to keep this change as small as possible. The current Python script swallows errors if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm inclined to agree with Rod. If this fails a bunch of tests will (should?) fail anyways. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Replacing comment I just deleted because, uh, wrong topic. Let's try again.) Can we do that as a separate PR? As with the expose-refresh-and-put-in-individual-tests, I'm happy to do it and even excited to do it because it's The Right Thing to do. But I want to keep the scope of the individual change sets as narrow and manageable as possible. If that change does break something when jenkins is run, I wouldn't want that change to hold up the rest of the stuff that's here. |
||
} 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think my preference would be to make this callable by the individual tests rather than happening for each test, we're trying to speed up tests and this will just slow them down There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually - that comment probably isn't fair without actually benchmarking this, so I'll reserve judgement until someone does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current Python script deletes and creates the temporary directory for each and every test. This duplicates that functionality. Making it something the individual tests call might be a decent performance win but it would also be a more invasive change, touching a lot of tests. I'd rather do that as two separate PRs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I've got this (tmp dir refreshing handled by individual tests so it only happens for tests that use the tmp dir) ready to go once this PR goes through. |
||
|
||
var opensslCli = null; | ||
var inFreeBSDJail = null; | ||
var localhostIPv4 = null; | ||
|
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]); | ||
|
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]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway we are ignoring this error code. Should we really need this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about the check in line 43?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That is kind of no-op in this context. Don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. I modeled it on https://github.com/isaacs/rimraf/blob/db4936530293eae3372ffe757fad2f378b1261c5/rimraf.js#L317-L318. I wonder if it's a hot path in that context. Anyway, I'll take it out and push another commit.