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

Adapter Failed to Load #958 #2156

Merged
merged 25 commits into from Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
98cfefc
committing changes for #958 fix
DineshChirnanchu Sep 5, 2019
5081873
committing changes for #958 fix
DineshChirnanchu Sep 5, 2019
f7bb50c
committing tests fixes #958
DineshChirnanchu Sep 6, 2019
6b64b05
Merge remote-tracking branch 'upstream/master'
DineshChirnanchu Sep 6, 2019
0aab6d0
Merge branch 'master' into AdapterFailedToLoad
DineshChirnanchu Sep 6, 2019
3d2ceeb
commtting fixes for tests #958
DineshChirnanchu Sep 6, 2019
520272c
Updated handle class name and downgraded TestMessageLevel Error to Wa…
DineshChirnanchu Sep 10, 2019
1c938a4
Merge remote-tracking branch 'upstream/master'
DineshChirnanchu Sep 12, 2019
e89a48c
commit changes to print specific error messages in each case of adapt…
DineshChirnanchu Sep 12, 2019
65418b7
committing new tests for #958
DineshChirnanchu Sep 13, 2019
c291d2d
Code changes refined #958
DineshChirnanchu Sep 16, 2019
1fc1a8a
LogWarningOnNoTestsDiscovered change reverted
DineshChirnanchu Sep 16, 2019
40f5291
commit changes improve test results
DineshChirnanchu Sep 19, 2019
2b8895b
Merge branch 'master' of https://github.com/DineshChirnanchu/vstest
DineshChirnanchu Sep 19, 2019
8dbee95
commit latest changes
DineshChirnanchu Sep 19, 2019
0410144
commtting latest changes
DineshChirnanchu Sep 20, 2019
3e62089
Merge remote-tracking branch 'upstream/master'
DineshChirnanchu Sep 20, 2019
f6df00e
Merge branch 'master' into AdapterFailedToLoad
DineshChirnanchu Sep 20, 2019
afd4420
Reverted TestRunMessage handler unsubscription
DineshChirnanchu Sep 20, 2019
7211af9
Unsubscribed testRunMessage session
DineshChirnanchu Sep 20, 2019
6ab126a
latest changes
DineshChirnanchu Sep 20, 2019
c38ecae
Amendments have been done
DineshChirnanchu Sep 23, 2019
96f69f6
Format corrected
DineshChirnanchu Sep 25, 2019
da55993
Merge remote-tracking branch 'upstream/master'
DineshChirnanchu Sep 25, 2019
1868b1d
Merge branch 'master' into AdapterFailedToLoad
DineshChirnanchu Sep 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,7 +12,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

Expand Down Expand Up @@ -138,6 +140,12 @@ private void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
this.GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(assembly, pluginInfos);
}
}
catch (FileLoadException e)
{
EqtTrace.Warning("TestPluginDiscoverer: Failed to load extensions from file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e);
string fileLoadErrorMessage = $"TestPluginDiscoverer: Failed to load extensions from file '" + file + "'";
TestSessionMessageLogger.Instance.SendMessage(TestMessageLevel.Error, fileLoadErrorMessage);
}
catch (Exception e)
{
EqtTrace.Warning("TestPluginDiscoverer: Failed to load extensions from file '{0}'. Skipping test extension scan for this file. Error: {1}", file, e);
Expand Down
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

discoveryEventsHandler [](start = 116, length = 22)

should be testExtensionInitializeEventsHandler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will go ahead with this once we finalize the permanent fix for it

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

move private to bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved under private methods region

{
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,7 @@ public void TestCleanup()
public void DiscoverTestsShouldCallInitialize()
{
var manualResetEvent = new ManualResetEvent(false);

this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>())).Callback(
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>(), null)).Callback(
() => manualResetEvent.Set());

var discoveryCriteria = new DiscoveryCriteria(new[] { "test.dll" }, 1, string.Empty);
Expand All @@ -62,7 +61,7 @@ public void DiscoverTestsShouldCallInitialize()
public void DiscoverTestsShouldUpdateTestPluginCacheWithExtensionsReturnByTestHost()
{
var manualResetEvent = new ManualResetEvent(false);
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>())).Callback(
this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty<string>(), null)).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>(), It.IsAny<ITestMessageEventHandler>()), 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 @@ -179,7 +179,7 @@ public void ProcessRequestsDiscoveryInitializeShouldSetExtensionPaths()
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"))), It.IsAny<ITestDiscoveryEventsHandler2>()));
this.SendSessionEnd();
}

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

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"))), It.IsAny<ITestMessageEventHandler>()));
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