Coverlet fails to write coverage with file locked error
See original GitHub issueSo this is a bit odd, but it only happens during our CI (and it is intermittent). We’re using v1.2 of the vstest collector.
The error we get is this:
Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to get coverage result
---> System.IO.IOException: The process cannot access the file '/tmp/MySourceProject_8b9f64e1-2aa6-4144-aece-e1ec4323d842' because it is being used by another process.
at System.IO.FileStream.Init(FileMode mode, FileShare share, String originalPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode)
at Coverlet.Core.Helpers.FileSystem.NewFileStream(String path, FileMode mode) in D:\git\coverletToRelease\src\coverlet.core\Helpers\FileSystem.cs:line 43
at Coverlet.Core.Coverage.CalculateCoverage() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 352
at Coverlet.Core.Coverage.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 137
at Coverlet.Collector.DataCollection.CoverageWrapper.GetCoverageResult(Coverage coverage) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageWrapper.cs:line 44
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 91
--- End of inner exception stack trace ---
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 96
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionEnd(Object sender, SessionEndEventArgs e) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverletCoverageCollector.cs:line 148.
What is strange is that after this error message, we see the last test case complete (we use the normal
logging verbosity so we see every test case printed). We’re using .net core 3.1, and xunit 2.4.1 if it matters (we use a xunit collection fixture too). It appears that the collection fixture is disposed before the last test’s results are printed whether coverlet succeeds or not, so I’m thinking the last test being printed out after the coverlet error is not an indication that it is actually running after coverlet is blocked.
Some other interesting info about our builds: It is in a docker container, with the test results directory mounted on a volume, so I can’t imagine another process is stepping on any file being used here. We pass a filter into dotnet test
because we have a number of expensive tests that we run in parallel by running multiple docker containers with different filters simultaneously.
When running 16.4.0
of the test sdk, we’d often see the error manifest as:
Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to get coverage result
---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.InternalRead(Int32 numBytes)
at Coverlet.Core.Coverage.CalculateCoverage() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 363
at Coverlet.Core.Coverage.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 137
at Coverlet.Collector.DataCollection.CoverageWrapper.GetCoverageResult(Coverage coverage) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageWrapper.cs:line 44
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 91
--- End of inner exception stack trace ---
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 96
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionEnd(Object sender, SessionEndEventArgs e) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverletCoverageCollector.cs:line 148.
But I’m only seeing the first error I posted with 16.5.0
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:60 (2 by maintainers)
Top GitHub Comments
I really appreciate your help @MarcoRossignoli! Here is the repository: https://github.com/namely/CoverletErrorRepro
If you can generate a repro would be great…I need to understand all the implication of my patches because tracker is a “sensible” component. For now use my branch patch if you can and I’ll do more investigation(busy weeks at the moment so I won’t merge to master soon). But I think this is definely a bug.