From 973200cfd3af473deead6a3a2ef03957c242e09e Mon Sep 17 00:00:00 2001 From: Bert Date: Mon, 18 Nov 2024 19:31:45 +0100 Subject: [PATCH] workaround for "Failed to instrument modules" (#1700) --- Documentation/KnownIssues.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/KnownIssues.md b/Documentation/KnownIssues.md index e14c2bfd7..b4c53e15e 100644 --- a/Documentation/KnownIssues.md +++ b/Documentation/KnownIssues.md @@ -249,3 +249,35 @@ Change [DebugType](https://learn.microsoft.com/en-us/dotnet/csharp/language-refe >[!IMPORTANT] >NET Core introduces a new symbol file (PDB) format - portable PDBs. Unlike traditional PDBs which are Windows-only, portable PDBs can be created and read on all platforms. + +## CoverletCoverageDataCollector: Failed to instrument modules + +*Affected drivers*: VSTest integration `dotnet test --collect:"XPlat Code Coverage"` + +*Symptoms:* + +```text +Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to instrument modules + ---> System.AggregateException: One or more errors occurred. (The process cannot access the file XXX\ABC.pdb + ---> System.IO.IOException: The process cannot access the file 'XXX\ABC.pdb' because it is being used by another process. + at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) + at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in /_/src/coverlet.core/Helpers/FileSystem.cs:line 35 + at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass16_0.b__1() in /_/src/coverlet.core/Helpers/InstrumentationHelper.cs:line 277 + at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.b__0() in /_/src/coverlet.core/Helpers/RetryHelper.cs:line 28 + at Coverlet.Core.Helpers.RetryHelper.Do[T](Func`1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in /_/src/coverlet.core/Helpers/RetryHelper.cs:line 55 + --- End of inner exception stack trace --- + ... + ``` + + >[!Note] + >This is not an coverlet issue but running tests in parallel without proper separation of test case resources + >> + >>**dotnet vstest cli option** + >> + >>--Parallel + >> + >> Run tests in parallel. By default, all available cores on the machine are available for use. Specify an explicit number of cores by setting the MaxCpuCount property under the RunConfiguration node in the runsettings file. + + *Solutions:* + + use VSTest setting [-maxcpucount:1](https://learn.microsoft.com/en-us/visualstudio/msbuild/building-multiple-projects-in-parallel-with-msbuild?view=vs-2022#-maxcpucount-switch) which limits "worker processes".