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

[WIP] Implement a VSTest data collector to write coverage data to disk #329

Closed
wants to merge 1 commit into from

Conversation

sharwell
Copy link
Contributor

Fixes #210

Still need to register the data collector using something like this.

@codecov
Copy link

codecov bot commented Jan 30, 2019

Codecov Report

Merging #329 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #329   +/-   ##
=======================================
  Coverage   86.57%   86.57%           
=======================================
  Files          16       16           
  Lines        2011     2011           
=======================================
  Hits         1741     1741           
  Misses        270      270


var unloadModule = injectedInstrumentationClass.GetMethod(nameof(ModuleTrackerTemplate.UnloadModule), new[] { typeof(object), typeof(EventArgs) });
if (unloadModule is null)
continue;
Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli Jan 30, 2019

Choose a reason for hiding this comment

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

Is this possible?Maybe this is "in process" code...binding flag etc...

@tonerdo
Copy link
Collaborator

tonerdo commented Jan 30, 2019

I remember trying to do this as the initial implementation. I found it hard to achieve the intended end user experience due to that RunSettings file. So resorted to injecting Coverlet into the MSBuild pipeline

@ViktorHofer
Copy link
Contributor

@sharwell can I somehow help you getting this done?

@MarcoRossignoli
Copy link
Collaborator

FYI we've added some new logging infos and seems that on my local I hit issue also with coverlet build #353

@MarcoRossignoli
Copy link
Collaborator

Still need to register the data collector using something like this.

@sharwell I did some test with collectors https://github.com/Microsoft/vstest-docs/blob/master/docs/extensions/datacollector.md and I saw that it works(deriving from DataCollector not InProc)) using simply command line

dotnet test ... --collect name --test-adapter-path path

question, why do we need config file?

@sharwell
Copy link
Contributor Author

why do we need config file?

No one previously knew how to enable it otherwise :)

Mpdreamz added a commit to elastic/elasticsearch-net that referenced this pull request Mar 25, 2019
* Move linux build to AppVeyor, no longer use Travis, update Readme to reflect move away from Travis and MyGet

* relax SDK check, falling behind is handled by dotnet CLI properly already

* move to dotnet test (xunit is removed in later versions)

* explicit test reporter

* coverlet does not work yet but hopeful coverlet-coverage/coverlet#329 fixes it in the future

* include integration tests on azure pipelines

* job names are not allowed spaces

* disable integration tests for now against master

* Update readme.md

Co-Authored-By: Mpdreamz <Mpdreamz@gmail.com>
Mpdreamz added a commit to elastic/elasticsearch-net that referenced this pull request Mar 25, 2019
* Move linux build to AppVeyor, no longer use Travis, update Readme to reflect move away from Travis and MyGet

* relax SDK check, falling behind is handled by dotnet CLI properly already

* move to dotnet test (xunit is removed in later versions)

* explicit test reporter

* coverlet does not work yet but hopeful coverlet-coverage/coverlet#329 fixes it in the future

* include integration tests on azure pipelines

* job names are not allowed spaces

* disable integration tests for now against master

* Update readme.md

Co-Authored-By: Mpdreamz <Mpdreamz@gmail.com>
(cherry picked from commit 67d9b69)
Mpdreamz added a commit to elastic/elasticsearch-net that referenced this pull request Mar 25, 2019
* Move linux build to AppVeyor, no longer use Travis, update Readme to reflect move away from Travis and MyGet

* relax SDK check, falling behind is handled by dotnet CLI properly already

* move to dotnet test (xunit is removed in later versions)

* explicit test reporter

* coverlet does not work yet but hopeful coverlet-coverage/coverlet#329 fixes it in the future

* include integration tests on azure pipelines

* job names are not allowed spaces

* disable integration tests for now against master

* Update readme.md

Co-Authored-By: Mpdreamz <Mpdreamz@gmail.com>
(cherry picked from commit 67d9b69)
Mpdreamz added a commit to elastic/elasticsearch-net that referenced this pull request Mar 25, 2019
* Move linux build to AppVeyor, no longer use Travis, update Readme to reflect move away from Travis and MyGet

* relax SDK check, falling behind is handled by dotnet CLI properly already

* move to dotnet test (xunit is removed in later versions)

* explicit test reporter

* coverlet does not work yet but hopeful coverlet-coverage/coverlet#329 fixes it in the future

* include integration tests on azure pipelines

* job names are not allowed spaces

* disable integration tests for now against master

* Update readme.md

Co-Authored-By: Mpdreamz <Mpdreamz@gmail.com>
(cherry picked from commit 67d9b69)
@yousifh
Copy link

yousifh commented Mar 26, 2019

I was testing this PR locally to see how it fixes the issue and I have a question about the implementation. With CoverletDataCollector calling UnloadModule when the test session is over, is the registration of the unload events in the Instrumenter.cs file required anymore?

In particular this block I think and maybe the code block below it as well? I'm not too familiar with this file

// Fixup the custom tracker class constructor, according to all instrumented types
if (_customTrackerRegisterUnloadEventsMethod == null)
{
    _customTrackerRegisterUnloadEventsMethod = new MethodReference(
        nameof(ModuleTrackerTemplate.RegisterUnloadEvents), module.TypeSystem.Void, _customTrackerTypeDef);
}

Instruction lastInstr = _customTrackerClassConstructorIl.Body.Instructions.Last();

if (!containsAppContext)
{
    // For "normal" cases, where the instrumented assembly is not the core library, we add a call to
    // RegisterUnloadEvents to the static constructor of the generated custom tracker. Due to static
    // initialization constraints, the core library is handled separately below.
    _customTrackerClassConstructorIl.InsertBefore(lastInstr, Instruction.Create(OpCodes.Call, _customTrackerRegisterUnloadEventsMethod));
}

I added few log statements and I can see UnloadModule being called twice, but I'm not sure if there is any consequences to that?

Mpdreamz added a commit to elastic/elasticsearch-net that referenced this pull request Mar 29, 2019
* Move linux build to AppVeyor, no longer use Travis, update Readme to reflect move away from Travis and MyGet

* relax SDK check, falling behind is handled by dotnet CLI properly already

* move to dotnet test (xunit is removed in later versions)

* explicit test reporter

* coverlet does not work yet but hopeful coverlet-coverage/coverlet#329 fixes it in the future

* include integration tests on azure pipelines

* job names are not allowed spaces

* disable integration tests for now against master

* Update readme.md

Co-Authored-By: Mpdreamz <Mpdreamz@gmail.com>
(cherry picked from commit 67d9b69)
@kamilon
Copy link

kamilon commented Apr 9, 2019

Is there an easy way to get a PreRelease NuGet of this (preferably in coverlet.msbuild package) so I can test this on a project that has these symptoms?

@MarcoRossignoli
Copy link
Collaborator

@kamilon usually I clone repo, checkout branch and build

msbuild build.proj /t:CreateNuGetPackage /p:Configuration=Release

you find nuget package C:\git\coverlet\build\Release\coverlet.msbuild.2.6.0.nupkg
After that you can use a Nuget.Config(custom on the root of your project or global) to refer to local coverlet package.

@MarcoRossignoli
Copy link
Collaborator

@sharwell let me know if you would like some help to go on with this, if you don't have free cycles I could give it a try!

@sandermvanvliet
Copy link

Just to chime in here, we're seeing the error from #210 pop up with both 2.5.0 and 2.6.0 on Azure DevOps. I'll see if I can run a test with a version in our private NuGet feed

@jmezach
Copy link

jmezach commented Apr 27, 2019

@MarcoRossignoli It looks like using the --collect and --test-adapter-path flags isn't going to work for this collector since it is an InProc one. Looking at this code from VSTest it looks like the only way to inject an in-process data collector is through the runsettings file.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Apr 27, 2019

@jmezach yes I saw, as I said above I did test deriving from DataCollector that isn't in proc, I wonder if it could work like in proc one to avoid settings file and use switches, it seems a simpler/more elegant approach to me.

@jmezach
Copy link

jmezach commented Apr 27, 2019

@MarcoRossignoli I tried that today, but it looks like I don't have access to the AppDomain where the instrumented code is running, so I can't call the Unload method from there. Or at least not that I can see.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Apr 27, 2019

I don't have access to the AppDomain where the instrumented code is running

I think that is the reason to use InProc...or maybe some with out of proc we need a way to "call test process", something like pipes or block TestSessionEnd with some shared event if possible in a cross plat way, but it seems overkill.

@MarcoRossignoli
Copy link
Collaborator

@sharwell we can close this we'll implement collectors as part of #395

@MarcoRossignoli
Copy link
Collaborator

Implemented in #410

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.

Spurious 'Unable to read beyond end of stream' in CI while collecting results
8 participants