-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix flaky unit test: linked_module_resolver_test #689
Merged
mhdawson
merged 2 commits into
paketo-buildpacks:main
from
sap-contributions:fix-flaky-tests
Jun 4, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
tbh: no idea why the test succeeded "most of the time"
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.
After "some" debugging: It worked in 2/3 of the cases because the resolved path in the test data has some subfolder.
1 of the 3 links is without subfolders and iterating over a dict in
go
doesn't give a guaranteed order.MkDirAll
will not fail for a r/o folder if the folder already exist and no subfolder is needed.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.
Using WriteFile seems different than creating a sub-directory. Do you have the output from when it fails? That would be good to understand why it was flaky and what the right fix might be.
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.
It is. That is the reason why it works now :) Imho,
WriteFile
is the correct tool for that anyway. Unfortunately, the tests are not that self explanatory and we had to make some assumptions. But in the end all made sense.You can just look in the pr validation of some other prs, e.g. #688 (it roughly happes 1/3 of the time)
We thought so as well, so after fixing it, we had a "little" debugging session to understand why the test is flaky. In a nutshell:
MkDirAll
go
, iterating over a dict is not ordered, but the order is randomWhen creating a file instead of directory, it works
MkDirAll
fails if you want to create a directory with the same name as a fileThere 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, the test is flaky.
On this part here
npm-install/linked_module_resolver_test.go
Line 134 in 7b388f0
If the first iteration that happens here
npm-install/linked_module_resolver.go
Line 58 in 7b388f0
npm-install/linked_module_resolver_test.go
Lines 45 to 67 in 7b388f0
/tmp/layer2780743255/sub-dir/src/packages
as thesub-dir
has permission0400
, this is what we expect and as a result the test passes. But in case of themodule-5
it will try to create the directory/tmp/layer2780743255/sub-dir
but because of the fact that it has sufficient permissions for the/tmp/layer2780743255
directorynpm-install/linked_module_resolver_test.go
Line 27 in 7b388f0
mkdirAll
function will not fail and will fail on the next if statementnpm-install/linked_module_resolver.go
Line 63 in 7b388f0
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.
So another solution in the current context could be
Which practically creates a sub-sub-directory with the proper permissions in order for the module-5 to fail.
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 sure that would fix the problem?
npm-install/linked_module_resolver.go
Line 63 in 7b388f0
Would still work because the directory already exists. I haven't checked it yet, though.