Closed AntiPasha closed 4 years ago
I've collected some events using Process Monitor, there no processes, except dotnet.exe
and testhost.exe
, accessing the file. During usual test run (without coverage) there is only file open, query information and locking file with only readers by testhost.exe
.
When coverage is run, there are a file reading, writing and locking file with only readers by both processes. After file is locked by testhost.exe
, dotnet.exe
is returning a sharing violation result when attempt to use a file for generic read and write. It seems that both processes have something like a race condition, when file is locked for reading by one process and second process attempts to access it with read/write access.
Attached two files with events, first one for run with /p:CollectCoverage=true
, second one with regular dotnet test
. Attempt to run with --collect:"XPlat Code Coverage" shows the same behavior with msbuild integration
coverlet_msbuild.xlsx
dotnet.test.xlsx
Can you try only with collectors and enable verbose logging and attach logs(before check if there are sensitive data inside) https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/Troubleshooting.md#collectors-integration? I want to understand if vstest plat logging show some contention exception.
Hi, please find verbose log for collectors attached. Thanks for your patience log.host.20-05-29_01-00-26_57408_4.txt log.txt log.datacollector.20-05-29_01-00-25_75553_4.txt
Thanks
I cannot repro and without stack trace of thread that blocks files it's hard to understand the reason, I've got a temporary idea to try, we could avoid to raise error in case of issue during file restoring, so at least you can get a coverage file output. Could work for the moment?The only drawback is that the files inside bin/debug will remain instrumented and so no more usable for further test run.
That errors happens at the end of all coverage when we copy back original(non instrumented) files, but at that time coverage data are correctly gathered.
@AntiPasha I'm working on a workaround/solution, can you try with this package(collectors driver dotnet test --collect:"XPlat Code Coverage"
)
nuget feed source https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json
package version 1.3.1-preview.6.g1f7fe02d13
This is the feed I use for preview/investigation.
Branch https://github.com/coverlet-coverage/coverlet/compare/master...MarcoRossignoli:issue857
@MarcoRossignoli Thanks a lot for the update, I've tried your package and it seems to work fine, I didn't seen any exceptions, report is generated in random folder under TestResults
, but in cobertura format. I thought that json
is default one, because I didn't use any settings
For collector the default one is cobertura as explained in the guide
If you confirm that amend works well I can merge and you can use nightly build until next official release
Does it work only for VSTest integration? What about msbuild one?
Works for both the engine in shared, but give me some minutes...I'll upload also msbuild version so you can try and confirm.
Uploaded coverlet.msbuild.2.9.1-preview.6.g1f7fe02d13
same feeds.
BTW my advice is to use collectors because has got better integration and doesn't suffer of some issues https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test
Please let me know if works as expected!
@MarcoRossignoli MSBuild integration works as well, thanks in advance!
Great will PR asap!
I do not think this has been released yet. Is there a release with this fix coming soon?
We should be near new release, we're discussing new versioning schema and after we'll release.
cc: @tonerdo
Good thread! I think we are on the same problem here. I managed to install the coverlet.collector.1.3.1-preview.6.g1f7fe02d13, but I can't seem to find the coverlet.msbuild.2.9.1-preview.6.g1f7fe02d13. Did you update to another preview?
Maybe I need the coverlet.msbuild, because I have a single test in a single class, causing this lockup, every time, it is not even intermittent for me. Currently, it is not open source code. I will see if I can produce an open example from the code.
The output is:
---> (Inner Exception #11) System.IO.IOException: The process cannot access the file 'C:\Jenkins\workspace\SharedUI\SharedUI-develop_builder\UnitTests\XUnit.Coverlet.Collector\bin\Debug\netcoreapp3.1\MessageFormatInterface.dll' because it is being used by another process. at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) at Coverlet.Core.Helpers.FileSystem.Copy(String sourceFileName, String destFileName, Boolean overwrite) in c:\git\coverlet\src\coverlet.core\Helpers\FileSystem.cs:line 33 at Coverlet.Core.Helpers.InstrumentationHelper.<>c__DisplayClass12_0.<RestoreOriginalModule>b__0() in c:\git\coverlet\src\coverlet.core\Helpers\InstrumentationHelper.cs:line 218 at Coverlet.Core.Helpers.RetryHelper.<>c__DisplayClass0_0.<Retry>b__0() in c:\git\coverlet\src\coverlet.core\Helpers\RetryHelper.cs:line 26 at Coverlet.Core.Helpers.RetryHelper.Do[T](Func
1 action, Func`1 backoffStrategy, Int32 maxAttemptCount) in c:\git\coverlet\src\coverlet.core\Helpers\RetryHelper.cs:line 52<---
--- End of inner exception stack trace --- at Coverlet.Collector.DataCollection.CoverageManager.InstrumentModules() in c:\git\coverlet\src\coverlet.collector\DataCollection\CoverageManager.cs:line 70 at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionStart(Object sender, SessionStartEventArgs sessionStartEventArgs) in c:\git\coverlet\src\coverlet.collector\DataCollection\CoverletCoverageCollector.cs:line 140.
Test Run Successful. Total tests: 1 Passed: 1 Total time: 3,6722 Seconds `
@xJom I apologize but we're in the middle of nightly migration and at the moment you can try with my unofficial feed I use to debug https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json
Keep the eyes on https://github.com/coverlet-coverage/coverlet/issues/969
Thanks! I managed to run it with 3.0.0-preview.9 for both coverlet.msbuild and coverlet.collector, but still one file is locking up. I have run it with both Process Monitor and search for locks in the ProcessExplorer - but I find nothing.
I also run with all parameters:
dotnet test /nodeReuse:false -m:1 .\XUnit.Coverlet.Collector.csproj /p:ParallelizeTestCollections=false /p:CopyLocalLockFileAssemblies=true /p:ExcludeFromCodeCoverage=MessageFormatInterface --collect:"XPlat Code Coverage"
But still no luck.
I also tried to turn off the Real-time protection of Microsoft Defender, but no difference. Since this is repeatable, it might have something to do with the structure of the test, but I am out of clues right now. Will discuss with a colleague.
Strange...keep me informed on it, also pls in case open a new issue this is boiled.
I am also running into this and the preview package has fixed it. Any plans to have a stable release for this? Thanks!
^^ Still running into this too
@danjcosg can you open a new issue?
This is a year later, and this problem still exists. Newest Coverlet Nuget, .NET 6 (or .NET Core 3.1 same). Was it ever fixed? I'm not allowed to use unofficial Nuget feeds so I haven't tried that.
The problem will always exist if some tool open handle to files when we want to restore the dll at the end, unfortunately we're not in control of that in any way.
One solution can be skip the restore(with some flag opt-in) if we're sure that the test build will be discarded at the end of the test and not used anymore outside testing.
The error message for MSBuild intergration
The same behavior for VSTest integration
It happens all the time, when I try to collect coverage for xunit test projects (with NUnit everything works fine suddenly) using default commands, like
dotnet test --collect:"XPlat Code Coverage"
ordotnet test /p:CollectCoverage=true
Adding
-nr:false -m:1
arguments to MSBuild didn't help, as well as running commands with separatecsproj
file. I've used the latest versions ofcoverlet
,xunit
andMicrosoft.NET.Test.Sdk
packagesInstalled SDKs are below
Migrated from comments of 725 issue