Skip to content

Commit

Permalink
Flow warnings to IDE (#1946)
Browse files Browse the repository at this point in the history
* Warnings should flow to IDE. Make sure all the warnings logged before the request is created are logged and sent to the IDE.
  • Loading branch information
singhsarab authored Mar 20, 2019
1 parent 89c02f9 commit d5d56a7
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ public void SendRawMessage(string rawMessage)
this.communicationManager.SendRawMessage(rawMessage);
}

/// <inheritdoc />
public void SendTestMessage(TestMessageLevel level, string message)
{
var payload = new TestMessagePayload { MessageLevel = level, Message = message };
this.communicationManager.SendMessage(MessageType.TestMessage, payload);
}

private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool skipTestHostLaunch)
{
Task.Run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
{
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

/// <summary>
/// Registers the discovery and test run events for designmode flow
Expand Down Expand Up @@ -60,5 +57,10 @@ private void OnRawMessageReceived(object sender, string rawMessage)
// Directly send the data to translation layer instead of deserializing it here
this.designModeClient.SendRawMessage(rawMessage);
}

public void LogWarning(string message)
{
this.designModeClient.SendTestMessage(TestMessageLevel.Warning, message);
}
}
}
20 changes: 14 additions & 6 deletions src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

/// <summary>
/// The interface for design mode client.
Expand All @@ -19,12 +20,6 @@ public interface IDesignModeClient : IDisposable
/// <param name="port">port number to connect</param>
void ConnectToClientAndProcessRequests(int port, ITestRequestManager testRequestManager);

/// <summary>
/// Send the raw messages to IDE
/// </summary>
/// <param name="rawMessage"></param>
void SendRawMessage(string rawMessage);

/// <summary>
/// Send a custom host launch message to IDE
/// </summary>
Expand All @@ -37,5 +32,18 @@ public interface IDesignModeClient : IDisposable
/// Handles parent process exit
/// </summary>
void HandleParentProcessExit();

/// <summary>
/// Send the raw messages to IDE
/// </summary>
/// <param name="rawMessage"></param>
void SendRawMessage(string rawMessage);

/// <summary>
/// Send the test session messages to IDE
/// </summary>
/// <param name="level">Level for the message</param>
/// <param name="message">Actual message string</param>
void SendTestMessage(TestMessageLevel level, string message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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.Common.Interfaces
{
public interface IBaseTestEventsRegistrar
{
/// <summary>
/// Log warning message before request is created.
/// </summary>
/// <param name="message">message string</param>
void LogWarning(string message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
namespace Microsoft.VisualStudio.TestPlatform.Common.Interfaces
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

public interface ITestDiscoveryEventsRegistrar
public interface ITestDiscoveryEventsRegistrar : IBaseTestEventsRegistrar
{
/// <summary>
/// Registers to receive discovery events from discovery request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
namespace Microsoft.VisualStudio.TestPlatform.Common.Interfaces
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

public interface ITestRunEventsRegistrar
public interface ITestRunEventsRegistrar : IBaseTestEventsRegistrar
{
/// <summary>
/// Registers to receive events from the provided test run request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.CommandLine;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal;
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Filtering;
Expand Down Expand Up @@ -246,6 +247,11 @@ public DiscoveryEventsRegistrar(IOutput output, TestCaseFilter filter, List<stri
this.options = cmdOptions;
}

public void LogWarning(string message)
{
ConsoleLogger.RaiseTestRunWarning(message);
}

public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
{
discoveryRequest.OnDiscoveredTests += this.discoveryRequest_OnDiscoveredTests;
Expand Down
6 changes: 6 additions & 0 deletions src/vstest.console/Processors/ListTestsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.CommandLine;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal;
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
Expand Down Expand Up @@ -232,6 +233,11 @@ public DiscoveryEventsRegistrar(IOutput output)
this.output = output;
}

public void LogWarning(string message)
{
ConsoleLogger.RaiseTestRunWarning(message);
}

public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
{
discoveryRequest.OnDiscoveredTests += this.discoveryRequest_OnDiscoveredTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal;
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
Expand Down Expand Up @@ -319,6 +320,11 @@ public DiscoveryEventsRegistrar(EventHandler<DiscoveredTestsEventArgs> discovere
this.discoveredTestsHandler = discoveredTestsHandler;
}

public void LogWarning(string message)
{
ConsoleLogger.RaiseTestRunWarning(message);
}

public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
{
discoveryRequest.OnDiscoveredTests += this.discoveredTestsHandler;
Expand Down
6 changes: 6 additions & 0 deletions src/vstest.console/Processors/RunTestsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal;
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces;
Expand Down Expand Up @@ -214,6 +215,11 @@ public TestRunRequestEventsRegistrar(IOutput output, CommandLineOptions commandL
this.commandLineOptions = commandLineOptions;
}

public void LogWarning(string message)
{
ConsoleLogger.RaiseTestRunWarning(message);
}

public void RegisterTestRunEvents(ITestRunRequest testRunRequest)
{
testRunRequest.OnRunCompletion += TestRunRequest_OnRunCompletion;
Expand Down
20 changes: 10 additions & 10 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove
}

var requestData = this.GetRequestData(protocolConfig);
if (this.UpdateRunSettingsIfRequired(runsettings, discoveryPayload.Sources?.ToList(), out string updatedRunsettings))
if (this.UpdateRunSettingsIfRequired(runsettings, discoveryPayload.Sources?.ToList(), discoveryEventsRegistrar, out string updatedRunsettings))
{
runsettings = updatedRunsettings;
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc
// Get sources to auto detect fx and arch for both run selected or run all scenario.
var sources = GetSources(testRunRequestPayload);

if (this.UpdateRunSettingsIfRequired(runsettings, sources, out string updatedRunsettings))
if (this.UpdateRunSettingsIfRequired(runsettings, sources, testRunEventsRegistrar, out string updatedRunsettings))
{
runsettings = updatedRunsettings;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ private void Dispose(bool disposing)
}
}

private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sources, out string updatedRunSettingsXml)
private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sources, IBaseTestEventsRegistrar registrar, out string updatedRunSettingsXml)
{
bool settingsUpdated = false;
updatedRunSettingsXml = runsettingsXml;
Expand All @@ -364,9 +364,9 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sou
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);
var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings();

settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, out Framework chosenFramework);
settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, registrar, out Framework chosenFramework);
settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, out Architecture chosenPlatform);
this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks);
this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar);
settingsUpdated |= this.UpdateDesignMode(document, runConfiguration);
settingsUpdated |= this.UpdateCollectSourceInformation(document, runConfiguration);
settingsUpdated |= this.UpdateTargetDevice(navigator, document, runConfiguration);
Expand Down Expand Up @@ -426,16 +426,16 @@ private bool UpdateDesignMode(XmlDocument document, RunConfiguration runConfigur
return updateRequired;
}

private void CheckSourcesForCompatibility(Framework chosenFramework, Architecture chosenPlatform, IDictionary<string, Architecture> sourcePlatforms, IDictionary<string, Framework> sourceFrameworks)
private void CheckSourcesForCompatibility(Framework chosenFramework, Architecture chosenPlatform, IDictionary<string, Architecture> sourcePlatforms, IDictionary<string, Framework> sourceFrameworks, IBaseTestEventsRegistrar registrar)
{
// Find compatible sources
var compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(chosenPlatform, chosenFramework, sourcePlatforms, sourceFrameworks, out var incompatibleSettingWarning);

// Raise warnings for incompatible sources
if (!string.IsNullOrEmpty(incompatibleSettingWarning))
{
EqtTrace.Info(incompatibleSettingWarning);
ConsoleLogger.RaiseTestRunWarning(incompatibleSettingWarning);
EqtTrace.Warning(incompatibleSettingWarning);
registrar.LogWarning(incompatibleSettingWarning);
}

// Log compatible sources
Expand Down Expand Up @@ -464,7 +464,7 @@ private bool UpdatePlatform(XmlDocument document, XPathNavigator navigator, List
return updatePlatform;
}

private bool UpdateFramework(XmlDocument document, XPathNavigator navigator, List<string> sources, IDictionary<string, Framework> sourceFrameworks, out Framework chosenFramework)
private bool UpdateFramework(XmlDocument document, XPathNavigator navigator, List<string> sources, IDictionary<string, Framework> sourceFrameworks, IBaseTestEventsRegistrar registrar, out Framework chosenFramework)
{
// Get framework from sources
var inferedFramework = inferHelper.AutoDetectFramework(sources, sourceFrameworks);
Expand All @@ -483,7 +483,7 @@ private bool UpdateFramework(XmlDocument document, XPathNavigator navigator, Lis
if (Constants.DotNetFramework35.Equals(chosenFramework.Name))
{
EqtTrace.Warning("TestRequestManager.UpdateRunSettingsIfRequired: throw warning on /Framework:Framework35 option.");
ConsoleLogger.RaiseTestRunWarning(Resources.Framework35NotSupported);
registrar.LogWarning(Resources.Framework35NotSupported);
}

return updateFramework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnTe
this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.ExecutionComplete, It.IsAny<TestRunCompletePayload>()), Times.Once());
}

[TestMethod]
public void DesignModeClientSendTestMessageShouldSendTestMessage()
{
var testPayload = new TestMessagePayload { MessageLevel = ObjectModel.Logging.TestMessageLevel.Error, Message = "DummyMessage" };

this.designModeClient.SendTestMessage(testPayload.MessageLevel, testPayload.Message);

this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny<TestMessagePayload>()), Times.Once());
}

private class TestableDesignModeClient : DesignModeClient
{
internal TestableDesignModeClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ public void RunTestsShouldNotThrowForFramework35()

this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig);

mockRunEventsRegistrar.Verify(lw => lw.LogWarning("Framework35 is not supported. For projects targeting .Net Framework 3.5, test will run in CLR 4.0 \"compatibility mode\"."), Times.Once);
mockTestPlatformEventSource.Verify(mt => mt.ExecutionRequestStart(), Times.Once);
mockTestPlatformEventSource.Verify(mt => mt.ExecutionRequestStop(), Times.Once);
}
Expand Down

0 comments on commit d5d56a7

Please sign in to comment.