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

Tests stability improvements #2362

Merged
merged 11 commits into from
Jan 2, 2017
Merged

Conversation

bestander
Copy link
Member

Summary

I am working on Ubuntu on Windows and had to fix a few issues with tests that were broken.

  • cache tests were slowed down because all of them were copying root folder to a temp location
  • if node is installed globally with root then global tests were failing for non root users
  • fixed a weird Ubuntu on Windows issue (going to report this over there)

@@ -41,13 +41,13 @@ export async function run(
const registry = config.registries[registryName];
const object = rootManifests[registryName].object;

for (const type of constants.DEPENDENCY_TYPES) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This construct was crashing node on ubuntu on windows.
I know it is not a good idea to patch Yarn because of a very niche environment but I could not find a nicer workaround

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this only happens only on Node 7 on ubuntu on windows.
Probably needs to be reported with Node.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'll revert this change and wait for Node to be stable then

Copy link
Member Author

Choose a reason for hiding this comment

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

Most likely related to nodejs/node#9419

} else {
cwd = path.join(
os.tmpdir(),
`yarn-${Math.random()}`,
Copy link
Member

Choose a reason for hiding this comment

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

Does Node.js provide a way to call the system's native temporary directory creation function (such as mkdtemp on GNU/Linux or GetTempFileName on Windows)? The issue with creating temporary directories like this is that two different processes (for example, running different tests in parallel) could generate the same random number.

Failing that, a GUID would be better too.

Copy link
Member

Choose a reason for hiding this comment

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

Just found that it does support it natively in Nodejs 5.10+: https://nodejs.org/api/fs.html#fs_fs_mkdtemp_prefix_options_callback

Copy link
Member

@Daniel15 Daniel15 left a comment

Choose a reason for hiding this comment

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

Use fs.mkdtemp if available, rather than yarn-${Math.random()}. The Math.random() could be used as a fallback for old Node.js versions (fs.mkdtemp is only available in Node.js 5 and above).

@bestander
Copy link
Member Author

Yeah, sounds reasonable.
Could not find a polyfill, I'll implement a with rand it then

@bestander
Copy link
Member Author

Actually nodejs/node#6142 makes me think that mdirtmp is quite useless for our case.
If I want to pass a prefix than I need to implement half of what fs.mkdtemp does and because I need to provide the polyfill anyway for Node 4 I'd better not to use Node's wrapper

@bestander
Copy link
Member Author

@Daniel15, how about now?

@Daniel15
Copy link
Member

Daniel15 commented Jan 1, 2017

This looks good to me, as Date.now should reduce the risk of collisions. It would be better to use the native functionality, but if Node.js doesn't expose that very well, it's fine to use some JS code for it.

Another option is to use something like node-tmp.

In any case, feel free to merge this whenever you like :)

@bestander bestander merged commit 52adb29 into yarnpkg:master Jan 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants