Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

Trott
Copy link
Member

@Trott Trott commented Jun 3, 2015

For tests run outside the python harness (for example to
see console.error() messages for debugging), common.js
should create the testing temp directory if it does not
exist.

ref: #1876

This change does not seem to result in a significant performance hit as far as I can tell, but I welcome better benchmarks than my "run time make test-parallel" methodology.

// Create tmpDir if it does not exist
if (! fs.existsSync(exports.tmpDir)) {
fs.mkdirSync(exports.tmpDir);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will print a deprecation warning. Should probably use fs.acessSync.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just try { fs.mkdirSync(exports.tmpDir) } catch (ex) {}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm...that will require a try/catch block which might have a more substantial affect on performance. Will try it anyway and see...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well technically fs.mkdirSync() could still throw too, for example if permissions are wrong somehow. I doubt it there would be a measurable impact for tests, but even if there was, there's always moving it to a separate function I suppose to limit the scope of the deopt...

@brendanashworth brendanashworth added the test Issues and PRs related to the tests. label Jun 3, 2015
@Trott
Copy link
Member Author

Trott commented Jun 3, 2015

New commit pushed to use fs.accessSync() instead of deprecated fs.existsSync().

@@ -20,6 +20,13 @@ if (process.env.TEST_THREAD_ID) {
}
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);

// Create tmpDir if it does not exist
try {
fs.accessSync(exports.tmpDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just try { fs.mkdirSync(exports.tmpDir); }? You don't need the accessSync() call at all then. And mkdirSync() being in the catch block is wrong because it can still throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that if there is no temp directory and creating the temp directory failed, I wanted the CLI to blow up. I should change it to what you have and catch EEXIST and rethrow other errors, or something like that...

@Fishrock123
Copy link
Contributor

See: #1876 (comment)

@Trott
Copy link
Member Author

Trott commented Jun 8, 2015

Pushed a new commit with POC attempt number 2.

Features/concerns:

  • Incorporated about 50 lines of code based on rimraf to do synchronous rm -rf. (Right way to attribute? Put it in a comment?)
  • Code smell: Checking for the existence of process.send to determine if the process is a child process or not. (We don't want to clean out the temp directories when a test forks or spawns.) Better solution there would be most welcome.
  • Had to remove unnecessary require('../common') from a couple fixtures because that was causing the temp directories to be cleaned out a second time and caused the tests to fail.
  • Had to fix test-fs-watch-recursive.js to ignore not just its own stale watch events but also stale watch events from other tests. See Test via iojs throws but python/make do not report error #1876 (comment)
  • Removed temp directory creation/cleaning from the Python code so it only happens in one place.
  • I've only tested this on my own computer. Would be curious to see how it does (or doesn't) work across different operating systems etc.

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.
@Trott
Copy link
Member Author

Trott commented Jun 9, 2015

Just pushed a minor commit that tweaks the proposed common.js code to make it more closely resemble the Python code it replaces.

@@ -12,6 +12,61 @@ exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
exports.isWindows = process.platform === 'win32';

var rimrafSync = function(p) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change these to simple named functions please, assigning to variables is not idiomatic for this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, new commit pushed with the function declarations changed to conform with the prevailing idiom already in the file!

Function declarations converted to idiomatic style
for common.js
@rvagg
Copy link
Member

rvagg commented Jun 9, 2015

https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/783/

this lgtm, anyone else want to signoff?

@Fishrock123
Copy link
Contributor

LGTM

fs.rmdirSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

@Trott
Copy link
Member Author

Trott commented Jun 10, 2015

I pushed a new commit based on observation by @thefourtheye. Can someone push this through Jenkins CI again to confirm that it doesn't trigger an edge case on a particular OS or anything? (I'm assuming I can't trigger Jenkins myself.)

@Fishrock123
Copy link
Contributor

@Trott
Copy link
Member Author

Trott commented Jun 10, 2015

Should I worry about the win2008r2 test failures? Or is that something that sort of just happens sometimes?

@Fishrock123
Copy link
Contributor

They appear unrelated.

@Trott
Copy link
Member Author

Trott commented Jun 10, 2015

So, given that two lines got deleted, once Jenkins finishes re-running, do we need to get a couple of LGTM's from the right folks again? /cc @Fishrock123 @rvagg (Does it need to re-run to see if the win2008r2 issues are just gremlins?) I'd love to get this in so I can pile some other stuff on top of it in other PRs before heading out to reportedly low-connectivity Walker Creek Ranch...

rvagg pushed a commit that referenced this pull request Jun 12, 2015
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 <rod@vagg.org>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@rvagg
Copy link
Member

rvagg commented Jun 12, 2015

Landed @ a6b8ee1, squashed into a single commit. didn't realise there were 3 until I started the process so I did the squash myself but in future @Trott maybe you could try and keep the PR to a single commit unless you're doing complex work across different concerns. It's sometimes handy to have multiple commits for review but they need to be squashed before landing so I tend to just --amend my single PR commits as I make changes and --force them up.

Thanks for the contribution and I look forward to seeing the additional improvements you have here!

@rvagg rvagg closed this Jun 12, 2015
@Trott
Copy link
Member Author

Trott commented Jun 12, 2015

Thanks @rvagg. I wasn't sure if I should squash everything every time or do one big squash after a couple of LGTMs so that people could follow along with the evolution of the changes if they wanted to. I had been doing both depending on what felt right for the particular situation. I'll try to make a point to always just squash squash squash (unless there's a super-compelling reason not to).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants