-
Notifications
You must be signed in to change notification settings - Fork 388
when "dotnet test" runs test projects in parallel mode, json file writes invalid #351
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
Conversation
dotnet test --no-build /p:CollectCoverage=true /p:CoverletOutputFormat='json%2copencover' /p:CoverletOutput="../results/coverage" /p:MergeWith="../results/coverage.json" /p:Exclude="[coverlet.*.tests?]*" ../results/coverage.json may faces concurrency problem, so when making the file share mode be none, it will solve the problem
Codecov Report
@@ Coverage Diff @@
## master #351 +/- ##
=========================================
+ Coverage 87.05% 87.1% +0.04%
=========================================
Files 31 31
Lines 3114 3125 +11
=========================================
+ Hits 2711 2722 +11
Misses 403 403 |
src/coverlet.core/Coverage.cs
Outdated
@@ -32,7 +30,9 @@ public string Identifier | |||
get { return _identifier; } | |||
} | |||
|
|||
public Coverage(string module, string[] includeFilters, string[] includeDirectories, string[] excludeFilters, string[] excludedSourceFiles, string[] excludeAttributes, bool singleHit, string mergeWith, bool useSourceLink) | |||
public Coverage(string module, string[] includeFilters, string[] includeDirectories, string[] excludeFilters, |
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.
Please could you revert formatting to old one here and on other places?
return reader.ReadToEnd(); | ||
} | ||
} | ||
}, () => TimeSpan.FromMilliseconds(100), 5); |
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.
|
||
if (!string.IsNullOrEmpty(_mergeWith) && !string.IsNullOrWhiteSpace(_mergeWith) && File.Exists(_mergeWith)) | ||
{ | ||
string json = File.ReadAllText(_mergeWith); | ||
var json = RetryHelper.Do(() => |
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.
Please can you add some comment above like // Possible concurrency access to merge file between write/read on parallel testing
here and below?
@loning I'm not very clear the problem this PR is trying to solve |
I have lots of unit test project under one solution, and when we call "dotnet test any.sln", the unit test project will run in parallel at the same time, when we use /p:CoverletOutput="../results/coverage" /p:MergeWith="../results/coverage.json", may two project will write to ../results/coverage.json at the same time, and also when other project want to merge, it may read a file not completed. so my solution is to make the file not shared, and when we cannot access a file, we wait 100ms, cause 100ms is enough for another read or write |
I just found once error, and rerun the CI, disappeared. but I thought it's not hard to fix it |
@loning run coverlet solution wide is not a supported scenario for now #350 (comment) |
thanks,@MarcoRossignoli,but it seems worked well in our solution, we do not want to use shell to run test one by one |
dotnet test --no-build /p:CollectCoverage=true /p:CoverletOutputFormat='json%2copencover' /p:CoverletOutput="../results/coverage" /p:MergeWith="../results/coverage.json" /p:Exclude="[coverlet..tests?]"
../results/coverage.json may faces concurrency problem, so when making the file share mode be none, it will solve the problem