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

InProc datacollector flow changes for passing test sources #1969

Merged
merged 12 commits into from
Apr 3, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using System.Collections.Generic;
abhishkk marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The Test Case level events.
Expand Down Expand Up @@ -33,7 +34,7 @@ public interface ITestCaseEventsHandler
/// Send session start event.
/// The purpose of this is to perform any initialization before the test case level events are sent.
/// </summary>
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
void SendSessionStart();
void SendSessionStart(IDictionary<string, object> properties);

/// <summary>
/// Sends session end event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollector.InProcDataCollector;
Expand Down Expand Up @@ -39,13 +39,16 @@ internal class InProcDataCollectionExtensionManager
/// <param name="testEventsPublisher">
/// The data collection test case event manager.
/// </param>
public InProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher testEventsPublisher)
/// <param name="sources">
/// The test sources
/// </param>
public InProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher testEventsPublisher, IEnumerable<string> sources)
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
{
this.InProcDataCollectors = new Dictionary<string, IInProcDataCollector>();
this.inProcDataCollectionSink = new InProcDataCollectionSink();

// Initialize InProcDataCollectors
this.InitializeInProcDataCollectors(runSettings);
this.InitializeInProcDataCollectors(runSettings, Path.GetDirectoryName(sources.FirstOrDefault()));
abhishkk marked this conversation as resolved.
Show resolved Hide resolved

if (this.IsInProcDataCollectionEnabled)
{
Expand Down Expand Up @@ -80,7 +83,7 @@ protected virtual IInProcDataCollector CreateDataCollector(DataCollectorSettings
dataCollectorSettings.CodeBase,
dataCollectorSettings.AssemblyQualifiedName,
interfaceTypeInfo,
dataCollectorSettings.Configuration.OuterXml);
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
dataCollectorSettings.Configuration != null ? dataCollectorSettings.Configuration.OuterXml : string.Empty);

inProcDataCollector.LoadDataCollector(this.inProcDataCollectionSink);

Expand All @@ -97,8 +100,8 @@ protected virtual IInProcDataCollector CreateDataCollector(DataCollectorSettings
/// The e.
/// </param>
private void TriggerTestSessionStart(object sender, SessionStartEventArgs e)
{
TestSessionStartArgs testSessionStartArgs = new TestSessionStartArgs();
{
TestSessionStartArgs testSessionStartArgs = new TestSessionStartArgs(e.GetPropertyValue<IEnumerable<string>>("TestSources"));
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
this.TriggerInProcDataCollectionMethods(Constants.TestSessionStartMethodName, testSessionStartArgs);
}

Expand Down Expand Up @@ -169,10 +172,10 @@ private void TriggerUpdateTestResult(object sender, TestResultEventArgs e)
/// <param name="runSettings">
/// The run Settings.
/// </param>
private void InitializeInProcDataCollectors(string runSettings)
private void InitializeInProcDataCollectors(string runSettings, string defaultCodeBase)
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
{
// Check if runsettings contains in-proc datacollector element
var inProcDataCollectionRunSettings = XmlRunSettingsUtilities.GetInProcDataCollectionRunSettings(runSettings);
var inProcDataCollectionSettingsPresentInRunSettings = inProcDataCollectionRunSettings?.IsCollectionEnabled ?? false;
Expand All @@ -189,6 +192,8 @@ private void InitializeInProcDataCollectors(string runSettings)
var interfaceTypeInfo = typeof(InProcDataCollection).GetTypeInfo();
foreach (var inProcDc in this.inProcDataCollectorSettingsCollection)
{
inProcDc.CodeBase = Path.IsPathRooted(inProcDc.CodeBase) ? inProcDc.CodeBase : Path.Combine(defaultCodeBase, inProcDc.CodeBase);
abhishkk marked this conversation as resolved.
Show resolved Hide resolved

var inProcDataCollector = this.CreateDataCollector(inProcDc, interfaceTypeInfo);
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
this.InProcDataCollectors[inProcDataCollector.AssemblyQualifiedName] = inProcDataCollector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.EventHandlers
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
Expand Down Expand Up @@ -51,9 +52,9 @@ public void SendTestResult(TestResult result)
}

/// <inheritdoc />
public void SendSessionStart()
public void SendSessionStart(IDictionary<string, object> properties)
{
this.SessionStart.SafeInvoke(this, new SessionStartEventArgs(), "TestCaseEventsHandler.RaiseSessionStart");
this.SessionStart.SafeInvoke(this, new SessionStartEventArgs(properties), "TestCaseEventsHandler.RaiseSessionStart");
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void RunTests()
try
{
// Call Session-Start event on in-proc datacollectors
this.testCaseEventsHandler?.SendSessionStart();
this.SendSessionStart();

elapsedTime = this.RunTestsInternal();

Expand All @@ -230,7 +230,7 @@ public void RunTests()
finally
{
// Trigger Session End on in-proc datacollectors
this.testCaseEventsHandler?.SendSessionEnd();
this.SendSessionEnd();

try
{
Expand Down Expand Up @@ -288,6 +288,10 @@ internal void Cancel()

protected abstract void InvokeExecutor(LazyExtension<ITestExecutor, ITestExecutorCapabilities> executor, Tuple<Uri, string> executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle);

protected abstract void SendSessionStart();

protected abstract void SendSessionEnd();

#endregion

private void CancelTestRunInternal(ITestExecutor executor)
Expand All @@ -309,17 +313,6 @@ private void SetContext()
{
this.testRunCache = new TestRunCache(this.testExecutionContext.FrequencyOfRunStatsChangeEvent, this.testExecutionContext.RunStatsChangeEventTimeout, this.OnCacheHit);

// Initialize data collectors if declared in run settings.
if (DataCollectionTestCaseEventSender.Instance != null && XmlRunSettingsUtilities.IsDataCollectionEnabled(this.runSettings))
{
var outOfProcDataCollectionManager = new ProxyOutOfProcDataCollectionManager(DataCollectionTestCaseEventSender.Instance, this.testEventsPublisher);
}

if (XmlRunSettingsUtilities.IsInProcDataCollectionEnabled(this.runSettings))
{
var inProcDataCollectionExtensionManager = new InProcDataCollectionExtensionManager(this.runSettings, this.testEventsPublisher);
}

this.runContext = new RunContext();
this.runContext.RunSettings = RunSettingsUtilities.CreateAndInitializeRunSettings(this.runSettings);
this.runContext.KeepAlive = this.testExecutionContext.KeepAlive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.SettingsProvider;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;

/// <summary>
/// Orchestrates test execution related functionality for the engine communicating with the test host process.
Expand Down Expand Up @@ -85,6 +89,8 @@ public void StartTestRun(
{
try
{
InitializeDataCollectors(runSettings, testCaseEventsHandler as ITestEventsPublisher, adapterSourceMap);

this.activeTestRun = new RunTestsWithSources(this.requestData, adapterSourceMap, package, runSettings, testExecutionContext, testCaseEventsHandler, runEventsHandler);

this.activeTestRun.RunTests();
Expand Down Expand Up @@ -119,6 +125,8 @@ public void StartTestRun(
{
try
{
InitializeDataCollectors(runSettings, testCaseEventsHandler as ITestEventsPublisher, tests);

this.activeTestRun = new RunTestsWithTests(this.requestData, tests, package, runSettings, testExecutionContext, testCaseEventsHandler, runEventsHandler);

this.activeTestRun.RunTests();
Expand Down Expand Up @@ -196,6 +204,37 @@ private void LoadExtensions()
}
}

private void InitializeDataCollectors(string runSettings, ITestEventsPublisher testEventsPublisher, IEnumerable<TestCase> tests)
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
{
// Initialize data collectors if declared in run settings.
if (DataCollectionTestCaseEventSender.Instance != null && XmlRunSettingsUtilities.IsDataCollectionEnabled(runSettings))
{
var outOfProcDataCollectionManager = new ProxyOutOfProcDataCollectionManager(DataCollectionTestCaseEventSender.Instance, testEventsPublisher);
}

if (XmlRunSettingsUtilities.IsInProcDataCollectionEnabled(runSettings))
{
var inProcDataCollectionExtensionManager = new InProcDataCollectionExtensionManager(runSettings, testEventsPublisher, tests.Select(tc => tc.Source).Distinct());
}
}

private void InitializeDataCollectors(string runSettings, ITestEventsPublisher testEventsPublisher, Dictionary<string, IEnumerable<string>> adapterSourceMap)
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
{
IEnumerable<string> sources = new List<string>();
sources = adapterSourceMap?.Values.Aggregate(sources, (current, enumerable) => current.Concat(enumerable));

// Initialize data collectors if declared in run settings.
if (DataCollectionTestCaseEventSender.Instance != null && XmlRunSettingsUtilities.IsDataCollectionEnabled(runSettings))
{
var outOfProcDataCollectionManager = new ProxyOutOfProcDataCollectionManager(DataCollectionTestCaseEventSender.Instance, testEventsPublisher);
}

if (XmlRunSettingsUtilities.IsInProcDataCollectionEnabled(runSettings))
{
var inProcDataCollectionExtensionManager = new InProcDataCollectionExtensionManager(runSettings, testEventsPublisher, sources);
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ internal class RunTestsWithSources : BaseRunTests

private Dictionary<Tuple<Uri,string>, IEnumerable<string>> executorUriVsSourceList;

private ITestCaseEventsHandler testCaseEventsHandler;

public RunTestsWithSources(IRequestData requestData, Dictionary<string, IEnumerable<string>> adapterSourceMap, string package, string runSettings, TestExecutionContext testExecutionContext, ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler)
: this(requestData, adapterSourceMap, package, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler, null)
{
Expand All @@ -52,6 +54,7 @@ internal RunTestsWithSources(IRequestData requestData, Dictionary<string, IEnume
{
this.adapterSourceMap = adapterSourceMap;
this.executorUriVsSourceList = executorUriVsSourceList;
this.testCaseEventsHandler = testCaseEventsHandler;
}

protected override void BeforeRaisingTestRunComplete(bool exceptionsHitDuringRunTests)
Expand Down Expand Up @@ -203,5 +206,21 @@ private static string TestCaseFilterToShow(string testCaseFilter)

return testCaseFilterToShow;
}

protected override void SendSessionEnd()
{
this.testCaseEventsHandler?.SendSessionEnd();
}

protected override void SendSessionStart()
{
var properties = new Dictionary<string, object>();

IEnumerable<string> sources = new List<string>();
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
sources = adapterSourceMap?.Values.Aggregate(sources, (current, enumerable) => current.Concat(enumerable));

properties.Add("TestSources", sources);
this.testCaseEventsHandler?.SendSessionStart(properties);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution
using System;
using System.Collections.Generic;
using System.Diagnostics;

using System.Linq;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
Expand All @@ -24,6 +24,8 @@ internal class RunTestsWithTests : BaseRunTests

private Dictionary<Tuple<Uri, string>, List<TestCase>> executorUriVsTestList;

private ITestCaseEventsHandler testCaseEventsHandler;

public RunTestsWithTests(IRequestData requestData, IEnumerable<TestCase> testCases, string package, string runSettings, TestExecutionContext testExecutionContext, ITestCaseEventsHandler testCaseEventsHandler, ITestRunEventsHandler testRunEventsHandler)
: this(requestData, testCases, package, runSettings, testExecutionContext, testCaseEventsHandler, testRunEventsHandler, null)
{
Expand All @@ -45,6 +47,7 @@ internal RunTestsWithTests(IRequestData requestData, IEnumerable<TestCase> testC
{
this.testCases = testCases;
this.executorUriVsTestList = executorUriVsTestList;
this.testCaseEventsHandler = testCaseEventsHandler;
}

protected override void BeforeRaisingTestRunComplete(bool exceptionsHitDuringRunTests)
Expand All @@ -67,6 +70,18 @@ protected override void InvokeExecutor(LazyExtension<ITestExecutor, ITestExecuto
executor?.Value.RunTests(this.executorUriVsTestList[executorUri], runContext, frameworkHandle);
}

protected override void SendSessionEnd()
{
this.testCaseEventsHandler?.SendSessionEnd();
}

protected override void SendSessionStart()
{
var properties = new Dictionary<string, object>();
properties.Add("TestSources", this.testCases.Select(tc => tc.Source).Distinct());
this.testCaseEventsHandler?.SendSessionStart(properties);
}

/// <summary>
/// Returns the executor Vs TestCase list
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Microsoft.TestPlatform.ObjectModel/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ public static class Constants
/// </summary>
public const string InProcDataCollectorsSettingName = "InProcDataCollectors";

/// <summary>
/// Coverlet data collector friendlyname
/// </summary>
public const string CoverletDataCollectorFriendlyName = "XPlat Code Coverage";
abhishkk marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Coverlet data collector assembly qualified name
/// </summary>
public const string CoverletDataCollectorAssemblyQualifiedName = "Microsoft.TestPlatform.Extensions.CoverletCoverageDataCollector.CoverletCoverageDataCollector, Microsoft.TestPlatform.Extensions.CoverletCoverageDataCollector, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
abhishkk marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Coverlet data collector uri
/// </summary>
public const string CoverletDataCollectorUri = "datacollector://microsoft/CoverletCodeCoverage/1.0";

/// <summary>
/// Coverlet data collector codebase
/// </summary>
public const string CoverletDataCollectorCodebase = "coverletinprocdatacollector.dll";

/// <summary>
/// Name of collect dump option for blame.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollector.InProcDataCollector
{
using System;
using System.Collections.Generic;

/// <summary>
/// The test session start args.
Expand All @@ -18,6 +19,18 @@ public TestSessionStartArgs()
this.Configuration = String.Empty;
}

/// <summary>
/// Initializes a new instance of the <see cref="TestSessionStartArgs"/> class.
abhishkk marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="sources">
/// The configuration.
/// </param>
public TestSessionStartArgs(IEnumerable<string> sources)
{
this.Configuration = String.Empty;
this.Sources = sources;
}

/// <summary>
/// Initializes a new instance of the <see cref="TestSessionStartArgs"/> class.
/// </summary>
Expand All @@ -33,5 +46,10 @@ public TestSessionStartArgs(string configuration)
/// Gets or sets the configuration.
/// </summary>
public string Configuration { get; set; }

/// <summary>
/// Gets or sets the test sources.
/// </summary>
private IEnumerable<string> Sources;
}
}
Loading