Skip to content
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

Coverlet in-process collector is not loaded for version > 1.0.0 #2221

Merged
merged 8 commits into from
Nov 13, 2019

Conversation

MarcoRossignoli
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli commented Oct 10, 2019

Fixes for #2205

cc: @tonerdo

@msftclas
Copy link

msftclas commented Oct 10, 2019

CLA assistant check
All CLA requirements met.

@mayankbansal018
Copy link
Contributor

@vagisha-nidhi can you please look

@vagisha-nidhi
Copy link
Contributor

@MarcoRossignoli What is the status of this PR?

@MarcoRossignoli
Copy link
Contributor Author

@vagisha-nidhi I would like to test it on my test project...but I don't know the correct steps, can you link me some guide or describe how I can use my local build of test host?

@MarcoRossignoli
Copy link
Contributor Author

@vagisha-nidhi
Copy link
Contributor

@MarcoRossignoli You can gereate the local binaries by using build.cmd on the root folder. This will generate artifacts/Debug/net451/win7-x64 which contain all built binaries. You can just test your dll with vstest.console.exe abc.dll from this folder

@MarcoRossignoli
Copy link
Contributor Author

You can gereate the local binaries by using build.cmd on the root folder

@vagisha-nidhi if I want to update and re-test should I rebuild all or I can rebuild only specific project in visual studio?

@MarcoRossignoli
Copy link
Contributor Author

MarcoRossignoli commented Oct 23, 2019

@vagisha-nidhi I cannot load collectors

C:\git\vstest\artifacts\Debug\net451\win7-x64 (loadcoverlet -> origin)
λ vstest.console.exe "C:\git\coverletissue\collectorTest\XUnitTestProject1\bin\Debug\netcoreapp3.0\XUnitTestProject1.dll" --collect:"XPlat Code Coverage"
Microsoft (R) Test Execution Command Line Tool Version 16.4.0-dev
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Data collection : Unable to find a datacollector with friendly name 'XPlat Code Coverage'.

Data collection : Could not find data collector 'XPlat Code Coverage'

[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.0 (64-bit .NET Core 3.0.0)

[xUnit.net 00:00:00.65]   Discovering: XUnitTestProject1

[xUnit.net 00:00:00.71]   Discovered:  XUnitTestProject1

[xUnit.net 00:00:00.71]   Starting:    XUnitTestProject1

[xUnit.net 00:00:00.86]   Finished:    XUnitTestProject1

  V XUnitTestProject1.UnitTest1.Test1 [4ms]


Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1,8512 Seconds

C:\git\vstest\artifacts\Debug\net451\win7-x64 (loadcoverlet -> origin)

@vagisha-nidhi
Copy link
Contributor

You can gereate the local binaries by using build.cmd on the root folder

@vagisha-nidhi if I want to update and re-test should I rebuild all or I can rebuild only specific project in visual studio?

Just build the particular project where your changes are and replace the net451 binaries in the artifacts folder.

@vagisha-nidhi
Copy link
Contributor

@vagisha-nidhi I cannot load collectors

C:\git\vstest\artifacts\Debug\net451\win7-x64 (loadcoverlet -> origin)
λ vstest.console.exe "C:\git\coverletissue\collectorTest\XUnitTestProject1\bin\Debug\netcoreapp3.0\XUnitTestProject1.dll" --collect:"XPlat Code Coverage"
Microsoft (R) Test Execution Command Line Tool Version 16.4.0-dev
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Data collection : Unable to find a datacollector with friendly name 'XPlat Code Coverage'.

Data collection : Could not find data collector 'XPlat Code Coverage'

[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.0 (64-bit .NET Core 3.0.0)

[xUnit.net 00:00:00.65]   Discovering: XUnitTestProject1

[xUnit.net 00:00:00.71]   Discovered:  XUnitTestProject1

[xUnit.net 00:00:00.71]   Starting:    XUnitTestProject1

[xUnit.net 00:00:00.86]   Finished:    XUnitTestProject1

  V XUnitTestProject1.UnitTest1.Test1 [4ms]


Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1,8512 Seconds

C:\git\vstest\artifacts\Debug\net451\win7-x64 (loadcoverlet -> origin)

Oh I got it. The coverlet.collector targets file sets the test adapter path to its nuget location. This will happen only when dotnet test is being run. So you won't be able to load the collector. As far as I remember coverlet.collector with vstest.console.exe is broken due to some other reason as well.
For validating for dotnet test, what you can do is (since these inproc collector changes are inside test host only), replace these dlls in microsoft.testplatform.testhost nuget package. Make sure the version you are referring to is the version you have replaced the dlls in and the binaries should be netcore ones.
The location will be something like C:\Users\vanidhi\.nuget\packages\microsoft.testplatform.testhost\16.3.0\lib\netcoreapp2.1

@MarcoRossignoli MarcoRossignoli changed the title [WIP]Coverlet in-process collector is not loaded for version > 1.0.0 Coverlet in-process collector is not loaded for version > 1.0.0 Oct 24, 2019
@MarcoRossignoli
Copy link
Contributor Author

MarcoRossignoli commented Oct 24, 2019

@vagisha-nidhi did a test...I used my build package and updated custom nuget.config and overwritten Microsoft.TestPlatform.CrossPlatEngine to attach and all seem work as expected.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="Local" value="C:\git\coverlet\bin\Debug\Packages" />
    <add key="vstest" value="C:\git\vstest\artifacts\Debug\packages" />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>
...
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0-dev" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
    <PackageReference Include="coverlet.collector" Version="1.1.0" />
  </ItemGroup>
...

You can do a review.
One question, is there a way to dogfood vstest packages after eventual merge?

@@ -79,6 +79,27 @@ public void InProcDataCollectorShouldInitializeIfAssemblyContainsAnyInProcDataCo
Assert.AreEqual(this.inProcDataCollector.AssemblyQualifiedName, typeInfo.AssemblyQualifiedName);
}

[TestMethod]
public void InProcDataCollectorLoadCoverlet()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test verify that also if aqn shows version 1.0.0.0 we correctly load a version 9.9.9.9 of lib

@@ -0,0 +1,40 @@
using System.Reflection;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added custom test assets, fake coverlet.collector.dll lib

@MarcoRossignoli
Copy link
Contributor Author

MarcoRossignoli commented Oct 28, 2019

ping @vagisha-nidhi for review...maybe we can fix this before 3.1 release.

@ViktorHofer
Copy link
Member

@vagisha-nidhi @singhsarab can somebody please take a look? Marco asked me to ping you as this impacts coverlet. thanks.

@singhsarab
Copy link
Contributor

@vagisha-nidhi is OOF this week.
@mayankbansal018 you might want to take a look as well.

using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollector.InProcDataCollector;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.InProcDataCollector;

[assembly: AssemblyKeyFile("key.snk")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this key file for?

Copy link
Contributor Author

@MarcoRossignoli MarcoRossignoli Oct 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly 2 reason

  1. Without signed assembly I cannot compile I get an error that force me to have a strong name asm.
    image

  2. After this merge we have on backlog this Sign collector and update visibility coverlet-coverage/coverlet#566 so I'll update this key here and will amend test and alg to check also "public key token".

{
// If we're loading coverlet collector we skip to check the version of assembly
// to allow upgrade throught nuget package
filterPredicate = (x) => x.FullName.Equals(Constants.CoverletDataCollectorTypeName) && interfaceTypeInfo.IsAssignableFrom(x.GetTypeInfo());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayankbansal018 Should we make this default ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no, If I'm not mistaken that aqn is read from possible runsetting file so a user should have that assembly in local folder. The issue with coverlet is that we(you) inject hardcoded aqn if user provide --collect:"XPlat Code Coverage".
It works well for user provided collectors because there is always a runsettings file provided, but with coverlet don't, so we need a way to make it works for every version without runsettings file.
So my idea is to check only "trusted" type/lib name only for coverlet.
BTW I could miss something in the big picture.

@MarcoRossignoli
Copy link
Contributor Author

@mayankbansal018
Copy link
Contributor

@MarcoRossignoli Vagisha is OOF this week, she should be able to pick this up coming Monday, we apologize for the delay.

@MarcoRossignoli
Copy link
Contributor Author

@singhsarab I resolved the conflicts there was an error on string format.

Copy link
Contributor

@vagisha-nidhi vagisha-nidhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@MarcoRossignoli
Copy link
Contributor Author

@vagisha-nidhi is there a way to dogfood vstest packages?

@singhsarab singhsarab merged commit ca24ad0 into microsoft:master Nov 13, 2019
@MarcoRossignoli MarcoRossignoli deleted the loadcoverlet branch November 13, 2019 08:41
@vagisha-nidhi
Copy link
Contributor

@MarcoRossignoli Here is the myget link where the recent build gets uploaded https://dotnet.myget.org/feed/vstest/package/nuget/Microsoft.NET.Test.Sdk/16.5.0-preview-20191113-01
Also, I'll be releasing it today so you can use the release build as well.

@MarcoRossignoli
Copy link
Contributor Author

Thanks!

@MarcoRossignoli
Copy link
Contributor Author

Also, I'll be releasing it today so you can use the release build as well.

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants