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

Improve instrumentation tests #420

Merged

Conversation

MarcoRossignoli
Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli commented May 23, 2019

contributes to #387

@tonerdo @petli with this PR we've a way to test the "reality" of instrumentation and coverage calculation.

What we have:

  1. a new helper class RemoteExecutor.Invoke that allow us to run a "lambda" in remote process to avoid issue with statics and file locks 🚀 🚀 🚀
  2. new possible assertions on line/branches coverage
  3. we can "debug" all process, no more repro local build and reference+Debug.Launch...we can add "case" on test code and reproduce, fix and keep and run on every CI, I think this will improve the quality and keep control on new "compiler versions" crazyness autogencode.
  4. to allow this I added the infrastructure for a DI pattern, I needed only RetryHelper and IProcessExitHandler injection for now...but with this in place we can improve testability of all components that will become injectables ❤️ ❤️ ❤️ !

@MarcoRossignoli MarcoRossignoli requested review from tonerdo and petli May 23, 2019 11:44
@@ -0,0 +1,34 @@
using System;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tonerdo this is a key class, setup a "container" with all injectable services(for now only retry helper).
We have some "static" code(methods) so we need a domain wide model DependencyInjection.Current provide access to all services.
I used DI framework used by ASP.NET Code inside Microsoft.Extensions.DependencyInjection https://github.com/aspnet/Extensions

}
}

public static void Set(IServiceProvider serviceProvider)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this method needed to "plug new services collection" used by testing to pass mocked IRetryHelper aware of process exit and file locking.

@@ -7,8 +7,9 @@
using System.Reflection;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this file is the only file changed to use "container" low cost change.

@@ -1,3 +1,4 @@
using Coverlet.Core.Abstracts;
Copy link
Collaborator Author

@MarcoRossignoli MarcoRossignoli May 23, 2019

Choose a reason for hiding this comment

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

Here we simply make RetryHelper an injectable "instance" type that implements IRetryHelper.

<PackageReference Include="Mono.Cecil" Version="0.10.1" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
Copy link
Collaborator Author

@MarcoRossignoli MarcoRossignoli May 23, 2019

Choose a reason for hiding this comment

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

I change this to 10 because Newtosolft has got a bug on 9.0.1 and cannot use TypeConverter in a correct way, this lead to exception during serialization of CoveragePrepareResult in testing.
MSbuild/VSTest collectors does not load this version but version 10.0.1 this is the reason why it works today(unexpected 😄).
Maybe @vagisha-nidhi has got some details on this.

@@ -54,5 +60,48 @@ public void TestCoverageWithTestAssembly()

directory.Delete(true);
}

[Fact]
public void Condition_If()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tonerdo @petli start from here!
This is the code we need to write to test!


namespace Coverlet.Core.Samples.Tests
{
public class Conditions
Copy link
Collaborator Author

@MarcoRossignoli MarcoRossignoli May 23, 2019

Choose a reason for hiding this comment

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

Added new file for new "class" of tests.
Wrote a "pilot" test.

@MarcoRossignoli
Copy link
Collaborator Author

I need to fix post build copy on linux, let me fix

@MarcoRossignoli
Copy link
Collaborator Author

Fail on unix...I'm investigating.

@MarcoRossignoli
Copy link
Collaborator Author

Found the issue, race between RestoreOriginalModules and RestoreOriginalModule on msbuild/console/collector are in same AppDomain on test nope so they race on Copy/Delete on locked files.
I'll fix it.

@MarcoRossignoli MarcoRossignoli changed the title Improve instrumentation tests [WIP]Improve instrumentation tests May 23, 2019
@MarcoRossignoli MarcoRossignoli changed the title [WIP]Improve instrumentation tests Improve instrumentation tests May 23, 2019

namespace Coverlet.Core.Abstracts
{
public interface IProcessExitHandler
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need this service to plug a fake in child process to avoid race condition on restore module.
In normal condition(no exception) we restore modules during coverage calculation, after @ViktorHofer update we restore also other instrumented module on exit, on msbuild/console/collector we use a shared dictionary but on test we instrument and run on child process so parent/child race on restore/delete files.
On child test we'll do nop.

@MarcoRossignoli
Copy link
Collaborator Author

MarcoRossignoli commented May 23, 2019

Bonus, improved coverage
Pre

 +---------------+--------+--------+--------+
  | Module        | Line   | Branch | Method |
  +---------------+--------+--------+--------+
  | coverlet.core | 76,03% | 67,42% | 83,03% |
  +---------------+--------+--------+--------+

  +---------+--------+--------+--------+
  |         | Line   | Branch | Method |
  +---------+--------+--------+--------+
  | Total   | 76,03% | 67,42% | 83,03% |
  +---------+--------+--------+--------+
  | Average | 76,03% | 67,42% | 83,03% |
  +---------+--------+--------+--------+

Post

  +---------------+--------+--------+--------+
  | Module        | Line   | Branch | Method |
  +---------------+--------+--------+--------+
  | coverlet.core | 80,98% | 71,1%  | 88,82% |
  +---------------+--------+--------+--------+

  +---------+--------+--------+--------+
  |         | Line   | Branch | Method |
  +---------+--------+--------+--------+
  | Total   | 80,98% | 71,1%  | 88,82% |
  +---------+--------+--------+--------+
  | Average | 80,98% | 71,1%  | 88,82% |
  +---------+--------+--------+--------+

@tonerdo we lost codecov report.

@tonerdo tonerdo changed the title Improve instrumentation tests [WIP] Improve instrumentation tests May 24, 2019
@MarcoRossignoli MarcoRossignoli changed the title [WIP] Improve instrumentation tests Improve instrumentation tests May 25, 2019
@MarcoRossignoli
Copy link
Collaborator Author

@tonerdo great thank's for WIP!
Ready to review!

@MarcoRossignoli
Copy link
Collaborator Author

@tonerdo can you review this?So we can go on with "core instrumentation" fix and improve test coverage .

Copy link
Collaborator

@tonerdo tonerdo left a comment

Choose a reason for hiding this comment

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

LGTM!

@MarcoRossignoli MarcoRossignoli merged commit cca1668 into coverlet-coverage:master Aug 9, 2019
@MarcoRossignoli MarcoRossignoli deleted the remoteinvoker branch August 9, 2019 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement General enhancement request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants