Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Documentation/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,17 @@ Fire attach
System.Diagnostics.Debugger.Launch();
```

If you want debug in-process collector you need to set VSTEST_HOST_DEBUG(https://github.com/microsoft/vstest/issues/2158) environment variable
```
set VSTEST_HOST_DEBUG=1
```
Test host will wait for debugger
```
Starting test execution, please wait...
Logging Vstest Diagnostics in file: C:\git\coverletissue\collectorlog\XUnitTestProject1\log.txt
Host debugging is enabled. Please attach debugger to testhost process to continue.
Process Id: 800, Name: dotnet
```

**Every time you update code and rebuild new package remember to remove local nuget cache(`RMDIR "C:\Users\[winUser]\.nuget\packages\coverlet.collector" /S /Q`) otherwise you'll load old collector code because the package version wasn't changed**

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using coverlet.collector.Resources;
using Coverlet.Collector.Utilities;
using Coverlet.Core.Instrumentation;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollector.InProcDataCollector;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.InProcDataCollector;
Expand All @@ -12,8 +11,11 @@ namespace Coverlet.Collector.DataCollection
{
public class CoverletInProcDataCollector : InProcDataCollection
{
private readonly TestPlatformEqtTrace _eqtTrace = new TestPlatformEqtTrace();

public void Initialize(IDataCollectionSink dataCollectionSink)
{
_eqtTrace.Verbose("Initialize CoverletInProcDataCollector");
}

public void TestCaseEnd(TestCaseEndArgs testCaseEndArgs)
Expand All @@ -36,17 +38,14 @@ public void TestSessionEnd(TestSessionEndArgs testSessionEndArgs)

try
{
_eqtTrace.Verbose($"Calling ModuleTrackerTemplate.UnloadModule for '{injectedInstrumentationClass.Assembly.FullName}'");
var unloadModule = injectedInstrumentationClass.GetMethod(nameof(ModuleTrackerTemplate.UnloadModule), new[] { typeof(object), typeof(EventArgs) });
unloadModule.Invoke(null, new[] { null, EventArgs.Empty });
_eqtTrace.Verbose($"Called ModuleTrackerTemplate.UnloadModule for '{injectedInstrumentationClass.Assembly.FullName}'");
}
catch (Exception ex)
{
// Throw any exception if unload fails
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error("{0}: Failed to unload module with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
}

_eqtTrace.Error("{0}: Failed to unload module with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
Copy link
Collaborator Author

@MarcoRossignoli MarcoRossignoli Sep 17, 2019

Choose a reason for hiding this comment

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

@vagisha-nidhi I removed check EqtTrace.IsErrorEnabled here and on other place because I don't understand how I can define switch level using command dotnet test --collect:"Xplat code coverage" --diag:"diag.txt"
Again they're not used in all other place(out-of-proc collector), are used only for Info and in one place only for verbose.
Can you explain how it works?Or how can I pass log level for EqtTrace to dotnet test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@vagisha-nidhi I merged...let me know if it's a problem.

string errorMessage = string.Format(Resources.FailedToUnloadModule, CoverletConstants.InProcDataCollectorName);
throw new CoverletDataCollectorException(errorMessage, ex);
}
Expand All @@ -57,7 +56,7 @@ public void TestSessionStart(TestSessionStartArgs testSessionStartArgs)
{
}

private static Type GetInstrumentationClass(Assembly assembly)
private Type GetInstrumentationClass(Assembly assembly)
{
try
{
Expand All @@ -74,11 +73,7 @@ private static Type GetInstrumentationClass(Assembly assembly)
}
catch (Exception ex)
{
// Avoid crashing if reflection fails.
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning("{0}: Failed to get Instrumentation class with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
}
_eqtTrace.Warning("{0}: Failed to get Instrumentation class with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
return null;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/coverlet.collector/Utilities/TestPlatformEqtTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ public void Info(string format, params object[] args)
{
EqtTrace.Info($"[coverlet]{format}", args);
}

/// <summary>
/// Error logger
/// </summary>
/// <param name="format">Format</param>
/// <param name="args">Args</param>
public void Error(string format, params object[] args)
{
EqtTrace.Error($"[coverlet]{format}", args);
}
}
}