-
Notifications
You must be signed in to change notification settings - Fork 124
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
Implemented combine coverprofile in the case of rerun failed #387
base: main
Are you sure you want to change the base?
Implemented combine coverprofile in the case of rerun failed #387
Conversation
3313900
to
2df1e19
Compare
Looks like
|
1554d71
to
55e31ce
Compare
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.
Thank you for the PR! I appreciate the contribution.
I had a quick look and overall it sounds reasonable to me. I agree the test failure seems unrelated.
I will find some more time to review in more detail. Some test coverage would also be appreciated!
// gocovmerge takes the results from multiple `go test -coverprofile` runs and | ||
// merges them into one profile | ||
|
||
// Taken from: https://github.com/wadey/gocovmerge @ b5bfa59ec0adc420475f97f89b58045c721d761c |
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.
I think we may need to copy the license file
(https://github.com/wadey/gocovmerge/blob/master/LICENSE) into internal/coverprofile
to comply with the license.
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.
I added the LICENSE to the file header since it is only the file we copied over. Please let me know if this is good enough.
cmd/rerunfails.go
Outdated
// Even if there is errors, we still need to combine the | ||
// coverprofile files. | ||
if isCoverprofile { | ||
if err := coverprofile.Combine(mainProfile, newCoverprofile); err != nil { |
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 might be better to wait until all the attempts are complete and then combine all the files. That way we aren't re-reading the main file each time.
Would that work?
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, this would work and better.
One caveat is in the case of failure. When go test
fails, the coverage profile still contain information up to the test failures. In the case of failure re-run, if we error out, we should still have 1 valid coverage profile and not leave profiles un-combined. So leaving all the combine to the end may not be desirable.
If reading the main profile multiple times is a concern, I can parse the main profile 1 time upfront and save the combined profile in memory each time when combine the re-run profile. Would this work? Not too sure if the performance gain from this optimization would justify the complexity increase.
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 more thoughts, I implemented the logic as follow:
- each rerun will write the coverage profile into it's own file
- after each rerun, read the rerun coverage profile into memory and delete the file
- after all rerun is done before success, we combine all the rerun coverage profile with the main profile
This achieve 2 goals:
- Only reading the main coverage profile once.
- The coverage is valid upto the latest failed rerun and the rerun cover profile file is cleaned up
PTAL and let me know what you think.
55e31ce
to
5201f4b
Compare
@dnephin Please let me know if there is anything you would like me to follow up :) |
0cfa31f
to
c53ac02
Compare
@dnephin Let me know if there is anything else you would like me to fix :) |
@dnephin Ping again :) |
Fix #274
As discussed in #274, when
gotestsum
rerun failed test cases, thecoverprofile
gets overridden by the each calls to the underlyinggo test
, causing coverprofile to per in correct.I tested the code with the repros provided in #274: https://github.com/neiser/gotestsum-rerun-dependent-subtests/tree/master
The code is just a proof of concept. If the general approach is acceptable, then I will go ahead and clean up the PR with necessary unit tests and comments.
The general approach taken in this PR:
coverprofile
flag is discovered, we parse the flag to get the file path.go test
unmodified.