azurecode-coveragecoverlet

coverlet coverage report resulting in Microsoft.VisualStudio.Coverage.VanguardException


I'm trying to integrate Cobertura report generation in my azure pipeline. For that I've added coverlet.collector 3.0.3 in my .Net core test projects. Below is my yaml command for test run

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*Test/*.csproj'
    arguments: '--collect:"XPlat Code Coverage"  --settings CodeCoverage.runsettings --logger trx'
    publishTestResults: false

I use Reportgenerator task, to merge & publish coverage reports. This all works fine in one branch of my code ( an old branch, on which I started setting up pipeline a while back ). But when I'm trying to point to latest branch in the pipeline, I get error as below

Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason

I've checked almost everything in two branches, Microsoft.Net.Test.SDK, coverlet.collector, both are of identical version. I'm not sure what is making difference between 2 branches and what differences I should be looking for between 2 code branches, that could lead to such issue.

Full log in case of success and failure is added below.

Success(when using old branch)

C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work\489\s\XXXX.Business.Test\XXXX.Business.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work\489\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002

Copyright (c) Microsoft Corporation. All rights reserved.

Results File: I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_18_04.trx

Attachments:
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\5f62864f-6c2c-4188-ac02-0dc536b464b3\coverage.cobertura.xml
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\5f62864f-6c2c-4188-ac02-0dc536b464b3\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01.04_17_58.coverage
Test Run Successful.
Total tests: 6
Passed: 6
Total time: 3.8813 Seconds

Failure(when pointing to new branch)

C:\windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test I:\Agent-Win-R_work\489\s\XXXX.Test\XXXXBusiness.Test.csproj "--collect:XPlat Code Coverage" --settings CodeCoverage.runsettings --logger trx
Test run for I:\Agent-Win-R_work\489\s\XXXX.Business.Test\bin\Debug\netcoreapp3.1\XXXXWeb.Business.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Data collector 'Code Coverage' message: Data collector caught an exception of type 'Microsoft.VisualStudio.Coverage.VanguardException': 'Running event not received from CodeCoverage.exe. Check eventlogs for failure reason.'. More details: ..
Results File: I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\SVCGIDETFSProdBld01_MP-GIDE-522C_2021-07-01_04_12_42.trx

Attachments:
I:\Agent-Win-R_work\489\s\XXXX.Business.Test\TestResults\3839c24a-e17d-4d0d-9953-359388d5a940\coverage.cobertura.xml
Test Run Failed.
Total tests: 6
Passed: 6

I also came across this issue thread : https://github.com/microsoft/azure-pipelines-agent/issues/2839 where user suspected it to be an agent upgrade issue, but that does not seems to be the case for me, as I'm able to run it successfully for one branch of code.

Any suggestion or guidance is appreciated.


Solution

  • As I raised this question with Coverlet team, I got a quick response from them. They noticed something that I totally missed.

    Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002
    

    This was coming in my success log, which meant that Microsoft code coverage was running in parallel with Coverlet code coverage. They suspected we can get some odd errors if you have two code coverage collectors running at the same time, and that some timing issue between how tests are run in the two branches leads to the different behavior.

    As soon as I disabled Microsoft code coverage in my .runsettings file, the issue got resolved

    Earlier:

     <DataCollector friendlyName="XPlat code coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
          
    

    Now

    <DataCollector friendlyName="XPlat code coverage">