Skip to content

Commit

Permalink
committing changes for microsoft#958 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DineshChirnanchu committed Sep 5, 2019
1 parent 3ce317c commit 98cfefc
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 21 deletions.
Expand Up @@ -16,7 +16,7 @@ public interface IDiscoveryManager
/// Initializes the discovery manager.
/// </summary>
/// <param name="pathToAdditionalExtensions"> The path to additional extensions. </param>
void Initialize(IEnumerable<string> pathToAdditionalExtensions);
void Initialize(IEnumerable<string> pathToAdditionalExtensions, ITestDiscoveryEventsHandler2 eventHandler);

/// <summary>
/// Discovers tests
Expand Down
Expand Up @@ -18,7 +18,7 @@ public interface IExecutionManager
/// Initializes the execution manager.
/// </summary>
/// <param name="pathToAdditionalExtensions"> The path to additional extensions. </param>
void Initialize(IEnumerable<string> pathToAdditionalExtensions);
void Initialize(IEnumerable<string> pathToAdditionalExtensions, ITestMessageEventHandler testMessageEventsHandler);

/// <summary>
/// Starts the test run with sources.
Expand Down
@@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.EventHandlers
{
using System;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

/// <summary>
/// The test run events handler.
/// </summary>
public class TestExtensionInitializeEventsHandler : ITestMessageEventHandler
{
private ITestRequestHandler requestHandler;

/// <summary>
/// Initializes a new instance of the <see cref="TestExtensionInitializeEventsHandler"/> class.
/// </summary>
/// <param name="requestHandler">test request handler</param>
public TestExtensionInitializeEventsHandler(ITestRequestHandler requestHandler)
{
this.requestHandler = requestHandler;
}

/// <summary>
/// Handles a test run message.
/// </summary>
/// <param name="level"> The level. </param>
/// <param name="message"> The message. </param>
public void HandleLogMessage(TestMessageLevel level, string message)
{
switch ((TestMessageLevel)level)
{
case TestMessageLevel.Informational:
EqtTrace.Info(message);
break;

case TestMessageLevel.Warning:
EqtTrace.Warning(message);
break;

case TestMessageLevel.Error:
EqtTrace.Error(message);
break;

default:
EqtTrace.Info(message);
break;
}

this.requestHandler.SendLog(level, message);
}

public void HandleRawMessage(string rawMessage)
{
// No-Op
// TestHost at this point has no functionality where it requires rawmessage
}
}
}
Expand Up @@ -105,7 +105,7 @@ private void InitializeExtensions(IEnumerable<string> sources)

// We don't need to pass list of extension as we are running inside vstest.console and
// it will use TestPluginCache of vstest.console
discoveryManager.Initialize(Enumerable.Empty<string>());
discoveryManager.Initialize(Enumerable.Empty<string>(), null);
}
}
}
Expand Up @@ -144,7 +144,7 @@ private void InitializeExtensions(IEnumerable<string> sources)

// We don't need to pass list of extension as we are running inside vstest.console and
// it will use TestPluginCache of vstest.console
executionManager.Initialize(Enumerable.Empty<string>());
executionManager.Initialize(Enumerable.Empty<string>(), null);
}
}
}
Expand Up @@ -63,10 +63,10 @@ protected DiscoveryManager(IRequestData requestData, ITestPlatformEventSource te
/// Initializes the discovery manager.
/// </summary>
/// <param name="pathToAdditionalExtensions"> The path to additional extensions. </param>
public void Initialize(IEnumerable<string> pathToAdditionalExtensions)
public void Initialize(IEnumerable<string> pathToAdditionalExtensions, ITestDiscoveryEventsHandler2 eventHandler)
{
this.testPlatformEventSource.AdapterSearchStart();

this.testDiscoveryEventsHandler = eventHandler;
if (pathToAdditionalExtensions != null && pathToAdditionalExtensions.Any())
{
// Start using these additional extensions
Expand Down
Expand Up @@ -240,10 +240,11 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec
{
EqtTrace.Info("Discovery Session Initialize.");
this.testHostManagerFactoryReady.Wait();
var discoveryEventsHandler = new TestDiscoveryEventHandler(this);
var pathToAdditionalExtensions = this.dataSerializer.DeserializePayload<IEnumerable<string>>(message);
jobQueue.QueueJob(
() =>
testHostManagerFactory.GetDiscoveryManager().Initialize(pathToAdditionalExtensions), 0);
testHostManagerFactory.GetDiscoveryManager().Initialize(pathToAdditionalExtensions, discoveryEventsHandler), 0);
break;
}

Expand All @@ -265,10 +266,11 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec
{
EqtTrace.Info("Execution Session Initialize.");
this.testHostManagerFactoryReady.Wait();
var testExtensionInitializeEventsHandler = new TestExtensionInitializeEventsHandler(this);
var pathToAdditionalExtensions = this.dataSerializer.DeserializePayload<IEnumerable<string>>(message);
jobQueue.QueueJob(
() =>
testHostManagerFactory.GetExecutionManager().Initialize(pathToAdditionalExtensions), 0);
testHostManagerFactory.GetExecutionManager().Initialize(pathToAdditionalExtensions, testExtensionInitializeEventsHandler), 0);
break;
}

Expand Down
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.SettingsProvider;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
Expand All @@ -20,6 +21,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution
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.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;

/// <summary>
Expand All @@ -28,16 +30,35 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution
public class ExecutionManager : IExecutionManager
{
private readonly ITestPlatformEventSource testPlatformEventSource;

private BaseRunTests activeTestRun;

private IRequestData requestData;
private readonly TestSessionMessageLogger sessionMessageLogger;
private ITestMessageEventHandler testMessageEventsHandler;

/// <summary>
/// Initializes a new instance of the <see cref="ExecutionManager"/> class.
/// </summary>
public ExecutionManager(IRequestData requestData) : this(TestPlatformEventSource.Instance, requestData)
{
this.sessionMessageLogger = TestSessionMessageLogger.Instance;
this.sessionMessageLogger.TestRunMessage += this.TestSessionMessageHandler;
}

private void TestSessionMessageHandler(object sender, TestRunMessageEventArgs e)
{
if (this.testMessageEventsHandler != null)
{
this.testMessageEventsHandler.HandleLogMessage(e.Level, e.Message);
}
else
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning(
"ExecutionManager: Could not pass the log message '{0}' as the callback is null.",
e.Message);
}
}
}

/// <summary>
Expand All @@ -56,8 +77,9 @@ protected ExecutionManager(ITestPlatformEventSource testPlatformEventSource, IRe
/// Initializes the execution manager.
/// </summary>
/// <param name="pathToAdditionalExtensions"> The path to additional extensions. </param>
public void Initialize(IEnumerable<string> pathToAdditionalExtensions)
public void Initialize(IEnumerable<string> pathToAdditionalExtensions, ITestMessageEventHandler testMessageEventsHandler)
{
this.testMessageEventsHandler = testMessageEventsHandler;
this.testPlatformEventSource.AdapterSearchStart();

if (pathToAdditionalExtensions != null && pathToAdditionalExtensions.Any())
Expand Down
Expand Up @@ -48,8 +48,8 @@ public void TestCleanup()
public void DiscoverTestsShouldCallInitialize()
{
var manualResetEvent = new ManualResetEvent(false);

this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>())).Callback(
var mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>(), mockTestDiscoveryEventHandler.Object)).Callback(
() => manualResetEvent.Set());

var discoveryCriteria = new DiscoveryCriteria(new[] { "test.dll" }, 1, string.Empty);
Expand All @@ -62,7 +62,8 @@ public void DiscoverTestsShouldCallInitialize()
public void DiscoverTestsShouldUpdateTestPluginCacheWithExtensionsReturnByTestHost()
{
var manualResetEvent = new ManualResetEvent(false);
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>())).Callback(
var mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>(), mockTestDiscoveryEventHandler.Object)).Callback(
() => manualResetEvent.Set());

this.mockTestHostManager.Setup(o => o.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new List<string> { "C:\\DiscoveryDummy.dll" });
Expand Down
Expand Up @@ -48,9 +48,10 @@ public void TestCleanup()
public void StartTestRunShouldCallInitialize()
{
var testRunCriteria = new TestRunCriteria(new List<string> { "source.dll" }, 10);
var mockTestMessageEventHandler = new Mock<ITestMessageEventHandler>();
this.inProcessProxyExecutionManager.StartTestRun(testRunCriteria, null);

this.mockExecutionManager.Verify(o => o.Initialize(Enumerable.Empty<string>()), Times.Once, "StartTestRun should call Initialize if not already initialized");
this.mockExecutionManager.Verify(o => o.Initialize(Enumerable.Empty<string>(), mockTestMessageEventHandler.Object), Times.Once, "StartTestRun should call Initialize if not already initialized");
}

[TestMethod]
Expand Down
Expand Up @@ -52,11 +52,12 @@ public void TestCleanup()
public void InitializeShouldUpdateAdditionalExtenions()
{
var mockFileHelper = new Mock<IFileHelper>();
var mockLogger = new Mock<ITestDiscoveryEventsHandler2>();
mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny<string>())).Returns(false);
TestPluginCache.Instance = new TestableTestPluginCache();

this.discoveryManager.Initialize(
new string[] { typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location });
new string[] { typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location }, mockLogger.Object);

var allDiscoverers = TestDiscoveryExtensionManager.Create().Discoverers;

Expand Down
Expand Up @@ -174,12 +174,13 @@ public void ProcessRequestsVersionCheckShouldLogErrorIfDiagnosticsEnableFails()
public void ProcessRequestsDiscoveryInitializeShouldSetExtensionPaths()
{
var message = this.dataSerializer.SerializePayload(MessageType.DiscoveryInitialize, new[] { "testadapter.dll" });
var mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();
this.ProcessRequestsAsync(this.mockTestHostManagerFactory.Object);

this.SendMessageOnChannel(message);
this.jobQueue.Flush();

this.mockDiscoveryManager.Verify(d => d.Initialize(It.Is<IEnumerable<string>>(paths => paths.Any(p => p.Equals("testadapter.dll")))));
this.mockDiscoveryManager.Verify(d => d.Initialize(It.Is<IEnumerable<string>>(paths => paths.Any(p => p.Equals("testadapter.dll"))), mockTestDiscoveryEventHandler.Object));
this.SendSessionEnd();
}

Expand Down Expand Up @@ -218,13 +219,13 @@ public void DiscoveryCompleteShouldSendDiscoveryCompletePayloadOnChannel()
public void ProcessRequestsExecutionInitializeShouldSetExtensionPaths()
{
var message = this.dataSerializer.SerializePayload(MessageType.ExecutionInitialize, new[] { "testadapter.dll" });

var mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();
this.ProcessRequestsAsync(this.mockTestHostManagerFactory.Object);

this.SendMessageOnChannel(message);
this.jobQueue.Flush();

this.mockExecutionManager.Verify(e => e.Initialize(It.Is<IEnumerable<string>>(paths => paths.Any(p => p.Equals("testadapter.dll")))));
this.mockExecutionManager.Verify(e => e.Initialize(It.Is<IEnumerable<string>>(paths => paths.Any(p => p.Equals("testadapter.dll"))), mockTestDiscoveryEventHandler.Object));
this.SendSessionEnd();
}

Expand Down
Expand Up @@ -74,13 +74,13 @@ public void TestCleanup()
public void InitializeShouldLoadAndInitializeAllExtension()
{
var commonAssemblyLocation = typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location;

var mockTestMessageEventHandler = new Mock<ITestMessageEventHandler>();
TestPluginCacheTests.SetupMockExtensions(
new string[] { commonAssemblyLocation },
() => { });


this.executionManager.Initialize(new List<string> { commonAssemblyLocation });
this.executionManager.Initialize(new List<string> { commonAssemblyLocation }, mockTestMessageEventHandler.Object);

Assert.IsNotNull(TestPluginCache.Instance.TestExtensions);

Expand Down

0 comments on commit 98cfefc

Please sign in to comment.