From 0489b02f44c27c6a667415bd3a8890ac4f8408a1 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Mon, 2 Jul 2018 23:15:58 +0530 Subject: [PATCH 1/2] Fixing error messaging for the cancel during WaitForRequestHandlerConnection and LaunchHost --- .../DesignMode/DesignModeClient.cs | 3 +- .../Resources/Resources.Designer.cs | 59 ++++++++++--------- .../Resources/Resources.resx | 3 + .../Resources/xlf/Resources.cs.xlf | 5 ++ .../Resources/xlf/Resources.de.xlf | 5 ++ .../Resources/xlf/Resources.es.xlf | 5 ++ .../Resources/xlf/Resources.fr.xlf | 5 ++ .../Resources/xlf/Resources.it.xlf | 5 ++ .../Resources/xlf/Resources.ja.xlf | 5 ++ .../Resources/xlf/Resources.ko.xlf | 5 ++ .../Resources/xlf/Resources.pl.xlf | 5 ++ .../Resources/xlf/Resources.pt-BR.xlf | 5 ++ .../Resources/xlf/Resources.ru.xlf | 5 ++ .../Resources/xlf/Resources.tr.xlf | 5 ++ .../Resources/xlf/Resources.xlf | 5 ++ .../Resources/xlf/Resources.zh-Hans.xlf | 5 ++ .../Resources/xlf/Resources.zh-Hant.xlf | 5 ++ .../Utilities/CancellationTokenExtensions.cs | 23 ++++++++ .../Client/ProxyExecutionManager.cs | 21 +++---- .../Client/ProxyOperationManager.cs | 12 +++- .../DesignMode/DesignModeClientTests.cs | 2 +- .../Client/ProxyExecutionManagerTests.cs | 11 ++++ .../Client/ProxyOperationManagerTests.cs | 34 ++++++++++- 23 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index ab2c6f31f8..fafb7058e8 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -10,6 +10,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; @@ -262,7 +263,7 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat // Since the IDEs own user-UI-experience here, TP will let the custom host launch as much time as IDEs define it for their users WaitHandle.WaitAny(new WaitHandle[] { waitHandle, cancellationToken.WaitHandle }); - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowTestPlatformExceptionIfCancellationRequested(); this.onAckMessageReceived = null; diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs index 991e4f2a8c..8dfb3feae7 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs @@ -20,7 +20,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Resources { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -62,7 +62,16 @@ internal Resources() { } /// - /// Looks up a localized string similar to Diagnostic data adapter message: {0}. + /// Looks up a localized string similar to Cancelling the operation as requested.. + /// + internal static string CancellationRequested { + get { + return ResourceManager.GetString("CancellationRequested", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Data collection : {0}. /// internal static string DataCollectionMessageFormat { get { @@ -71,7 +80,7 @@ internal static string DataCollectionMessageFormat { } /// - /// Looks up a localized string similar to Diagnostic data adapter '{0}' failed to provide intialization information. Error: {1}. + /// Looks up a localized string similar to Data collector '{0}' failed to provide initialization information. Error: {1}. /// internal static string DataCollectorErrorOnGetVariable { get { @@ -80,7 +89,7 @@ internal static string DataCollectorErrorOnGetVariable { } /// - /// Looks up a localized string similar to The diagnostic data adapter '{0}' threw an exception during type loading, construction, or initialization: {1}.. + /// Looks up a localized string similar to Data collector '{0}' threw an exception during type loading, construction, or initialization: {1}.. /// internal static string DataCollectorInitializationError { get { @@ -89,7 +98,7 @@ internal static string DataCollectorInitializationError { } /// - /// Looks up a localized string similar to Diagnostic data adapter ('{0}') message: {1}.. + /// Looks up a localized string similar to Data collector '{0}' message: {1}.. /// internal static string DataCollectorMessageFormat { get { @@ -98,7 +107,7 @@ internal static string DataCollectorMessageFormat { } /// - /// Looks up a localized string similar to Could not find diagnostic data adapter of type '{0}' and Uri '{1}'. + /// Looks up a localized string similar to Could not find data collector '{0}'. /// internal static string DataCollectorNotFound { get { @@ -107,7 +116,7 @@ internal static string DataCollectorNotFound { } /// - /// Looks up a localized string similar to The diagnostic data adapter '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another diagnostic data adapter '{3}' has already requested same environment variable with different value '{4}'.. + /// Looks up a localized string similar to The data collector '{0}' requested environment variable '{1}' with value '{2}' to be set in test execution environment, but another data collector '{3}' has already requested same environment variable with different value '{4}'.. /// internal static string DataCollectorRequestedDuplicateEnvironmentVariable { get { @@ -134,7 +143,7 @@ internal static string DuplicateSettingsName { } /// - /// Looks up a localized string similar to Duplicated run settings section named '{0}' found. Ignoring the duplicate settings.. + /// Looks up a localized string similar to Duplicate run settings section named '{0}' found. Ignoring the duplicate settings.. /// internal static string DuplicateSettingsProvided { get { @@ -150,7 +159,7 @@ internal static string EmptyParenthesis { return ResourceManager.GetString("EmptyParenthesis", resourceCulture); } } - + /// /// Looks up a localized string similar to Failed to find the list of installed unit test extensions. Reason: {0}. /// @@ -159,20 +168,18 @@ internal static string FailedToFindInstalledUnitTestExtensions { return ResourceManager.GetString("FailedToFindInstalledUnitTestExtensions", resourceCulture); } } - + /// /// Looks up a localized string similar to An error occured while creating Fast filter.. /// - internal static string FastFilterException - { - get - { + internal static string FastFilterException { + get { return ResourceManager.GetString("FastFilterException", resourceCulture); } } - + /// - /// Looks up a localized string similar to There are multiple configurations that have diagnostic data adapter type '{0}' or Uri '{1}'. Duplicate configurations will be ignored in the test run.. + /// Looks up a localized string similar to There are multiple configurations that have data collector FriendlyName as '{0}'. Duplicate configurations will be ignored in the test run.. /// internal static string IgnoredDuplicateConfiguration { get { @@ -206,7 +213,7 @@ internal static string InvalidOperator { return ResourceManager.GetString("InvalidOperator", resourceCulture); } } - + /// /// Looks up a localized string similar to Exception occurred while initializing logger with {0}: '{1}'. The logger will not be used. Exception: {2}. /// @@ -215,7 +222,7 @@ internal static string LoggerInitializationError { return ResourceManager.GetString("LoggerInitializationError", resourceCulture); } } - + /// /// Looks up a localized string similar to Could not find a test logger with AssemblyQualifiedName, URI or FriendlyName '{0}'.. /// @@ -224,18 +231,16 @@ internal static string LoggerNotFound { return ResourceManager.GetString("LoggerNotFound", resourceCulture); } } - + /// /// Looks up a localized string similar to The Test Logger URI '{0}' is not valid. The Test Logger will be ignored.. /// - public static string LoggerUriInvalid - { - get - { + internal static string LoggerUriInvalid { + get { return ResourceManager.GetString("LoggerUriInvalid", resourceCulture); } } - + /// /// Looks up a localized string similar to Error: Missing ')'. /// @@ -273,7 +278,7 @@ internal static string MissingOperator { } /// - /// Looks up a localized string similar to Diagnostic data adapter caught an exception of type '{0}': '{1}'. More details: {2}.. + /// Looks up a localized string similar to Data collector caught an exception of type '{0}': '{1}'. More details: {2}.. /// internal static string ReportDataCollectorException { get { @@ -334,7 +339,7 @@ internal static string TestCaseFilterFormatException { return ResourceManager.GetString("TestCaseFilterFormatException", resourceCulture); } } - + /// /// Looks up a localized string similar to This option works only with vstest.console.exe installed as part of Visual Studio.. /// @@ -343,7 +348,7 @@ internal static string VSInstallationNotFound { return ResourceManager.GetString("VSInstallationNotFound", resourceCulture); } } - + /// /// Looks up a localized string similar to Types deriving from the data collection context cannot be used for sending data and messages. The DataCollectionContext used for sending data and messages must come from one of the events raised to the data collector.. /// diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx index 2a6bf42bc4..450bf809c0 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Cancelling the operation as requested. + Data collection : {0} diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf index 153393ba37..2306479745 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf @@ -264,6 +264,11 @@ Při vytváření rychlého filtru došlo k chybě. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf index d372422c2f..efed536857 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf @@ -264,6 +264,11 @@ Fehler beim Erstellen eines Schnellfilters. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf index 6ad536898a..745094db7e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf @@ -264,6 +264,11 @@ Error al crear el filtro rápido. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf index cec17d06e6..5521d954c2 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf @@ -264,6 +264,11 @@ Une erreur s'est produite lors de la création du filtre rapide. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf index 8fdb5e6819..cdaf47280c 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf @@ -264,6 +264,11 @@ Si è verificato un errore durante la creazione del filtro Fast. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf index 2b016167a2..b20a53b222 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf @@ -264,6 +264,11 @@ 高速フィルターを作成中にエラーが発生しました。 + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf index c806283393..397b19deed 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf @@ -264,6 +264,11 @@ 빠른 필터를 만드는 중 오류가 발생했습니다. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf index b3b07e2ed5..61bde9dbb1 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf @@ -264,6 +264,11 @@ Wystąpił błąd podczas tworzenia szybkiego filtru. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf index 3f71254f84..58a215e1bb 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf @@ -264,6 +264,11 @@ Ocorreu um erro ao criar o filtro Rápido. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf index db97f05f9f..029fc953fe 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf @@ -264,6 +264,11 @@ При создании быстрого (Fast) фильтра произошла ошибка. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf index 745166e812..36dc5e6985 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf @@ -264,6 +264,11 @@ Hızlı filtre oluşturulurken bir hata oluştu. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf index 7a9fc5dbd4..a89f0855a0 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf @@ -141,6 +141,11 @@ An error occured while creating Fast filter. + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf index 9b746da3ac..b88f0539f2 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf @@ -264,6 +264,11 @@ 创建“快”筛选器时遇到错误。 + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf index b84220396f..0a62c59c42 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf @@ -264,6 +264,11 @@ 建立快速篩選時發生錯誤。 + + Cancelling the operation as requested. + Cancelling the operation as requested. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs b/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs new file mode 100644 index 0000000000..8148229168 --- /dev/null +++ b/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs @@ -0,0 +1,23 @@ +// 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.Utilities +{ + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using System.Threading; + + public static class CancellationTokenExtensions + { + /// + /// Extension method used to throw TestPlatformException in case operation is cancelled. + /// + /// CancellationToken on which cancel is requested + public static void ThrowTestPlatformExceptionIfCancellationRequested(this CancellationToken token) + { + if (token.IsCancellationRequested) + { + throw new TestPlatformException(Resources.Resources.CancellationRequested); + } + } + } +} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index 574443d391..bff3240c48 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -7,11 +7,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; - using System.Threading; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; - using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; @@ -110,15 +109,8 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH if (this.isCommunicationEstablished) { - if (this.CancellationTokenSource.IsCancellationRequested) - { - if (EqtTrace.IsVerboseEnabled) - { - EqtTrace.Verbose("ProxyExecutionManager.StartTestRun: Canceling the current run after getting cancelation request."); - } - throw new TestPlatformException(Resources.Resources.CancelationRequested); - } - + this.CancellationTokenSource.Token.ThrowTestPlatformExceptionIfCancellationRequested(); + this.InitializeExtensions(testPackages); // This code should be in sync with InProcessProxyExecutionManager.StartTestRun executionContext @@ -154,9 +146,12 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH EqtTrace.Error("ProxyExecutionManager.StartTestRun: Failed to start test run: {0}", exception); // Log error message to design mode and CLI. - var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.ToString() }; + // TestPlatformException is expected exception, log only the message + // For other exceptions, log the stacktrace as well + var errorMessage = exception is TestPlatformException ? exception.Message : exception.ToString(); + var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = errorMessage }; this.HandleRawMessage(this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload)); - this.LogMessage(TestMessageLevel.Error, exception.ToString()); + this.LogMessage(TestMessageLevel.Error, errorMessage); // Send a run complete to caller. Similar logic is also used in ParallelProxyExecutionManager.StartTestRunOnConcurrentManager // Aborted is `true`: in case of parallel run (or non shared host), an aborted message ensures another execution manager diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 567999ef3d..e2b9929f49 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -10,8 +10,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Linq; using System.Reflection; using System.Threading; + using System.Threading.Tasks; using CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -24,7 +26,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using CrossPlatEngineResources = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources.Resources; using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources; using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants; - + /// /// Base class for any operations that the client needs to drive through the engine. /// @@ -99,7 +101,7 @@ protected ProxyOperationManager(IRequestData requestData, ITestRequestSender req /// public virtual bool SetupChannel(IEnumerable sources) { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + this.CancellationTokenSource.Token.ThrowTestPlatformExceptionIfCancellationRequested(); var connTimeout = EnvironmentHelper.GetConnectionTimeout(); if (!this.initialized) @@ -138,6 +140,11 @@ public virtual bool SetupChannel(IEnumerable sources) catch (Exception ex) { EqtTrace.Error("ProxyOperationManager: Failed to launch testhost :{0}", ex); + + if (ex is AggregateException && ex.InnerException is TaskCanceledException) + { + throw new TestPlatformException(Common.Resources.Resources.CancellationRequested); + } throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, CrossPlatEngineResources.FailedToLaunchTestHost, ex.ToString())); } @@ -158,6 +165,7 @@ public virtual bool SetupChannel(IEnumerable sources) if (!this.testHostLaunched || !this.RequestSender.WaitForRequestHandlerConnection(connTimeout * 1000, this.CancellationTokenSource.Token)) { + this.CancellationTokenSource.Token.ThrowTestPlatformExceptionIfCancellationRequested(); this.ThrowExceptionOnConnectionFailure(connTimeout); } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 264fd29bc6..abd58c571e 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -313,7 +313,7 @@ public void DesignModeClientLaunchCustomHostMustThrowIfInvalidAckComes() } [TestMethod] - [ExpectedException(typeof(OperationCanceledException))] + [ExpectedException(typeof(TestPlatformException))] public void DesignModeClientLaunchCustomHostMustThrowIfCancellationOccursBeforeHostLaunch() { var testableDesignModeClient = new TestableDesignModeClient(this.mockCommunicationManager.Object, JsonDataSerializer.Instance, this.mockPlatformEnvrironment.Object); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index 4cf35e633b..d0b21f25b0 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -402,6 +402,17 @@ public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageAndHandleLogM mockTestRunEventsHandler.Verify(s => s.HandleLogMessage(TestMessageLevel.Error, It.IsAny())); } + [TestMethod] + public void StartTestRunForCancelRequestShouldHandleLogMessageWithProperErrorMessage() + { + Mock mockTestRunEventsHandler = new Mock(); + this.testExecutionManager.Cancel(mockTestRunEventsHandler.Object); + + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + mockTestRunEventsHandler.Verify(s => s.HandleLogMessage(TestMessageLevel.Error, "Cancelling the operation as requested.")); + } + [TestMethod] public void StartTestRunShouldInitiateTestRunForSourcesThroughTheServer() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index e6457a5eae..a2211c3c9a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -235,7 +235,7 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() } [TestMethod] - public void SetupChannelShouldThrowIfRequestCancelled() + public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelled() { SetupTestHostLaunched(true); this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); @@ -244,7 +244,37 @@ public void SetupChannelShouldThrowIfRequestCancelled() var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); cancellationTokenSource.Cancel(); - Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); + var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; + StringAssert.Equals("Cancelling the operation as requested.", message); + } + + [TestMethod] + public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelledDuringLaunchOfTestHost() + { + SetupTestHostLaunched(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); + + this.mockTestHostManager.Setup(rs => rs.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Callback(() => Task.Run(() => { throw new OperationCanceledException(); })); + + var cancellationTokenSource = new CancellationTokenSource(); + var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); + + var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; + StringAssert.Equals("Cancelling the operation as requested.", message); + } + + [TestMethod] + public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelledPostHostLaunchDuringWaitForHandlerConnection() + { + SetupTestHostLaunched(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); + + var cancellationTokenSource = new CancellationTokenSource(); + this.mockTestHostManager.Setup(rs => rs.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Callback(() => cancellationTokenSource.Cancel()); + var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); + + var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; + StringAssert.Equals("Cancelling the operation as requested.", message); } [TestMethod] From dfaf10787b571b189653295fc22d3bc8ce17c4e8 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Thu, 5 Jul 2018 18:06:39 +0530 Subject: [PATCH 2/2] Changes as per comments. --- .../Utilities/CancellationTokenExtensions.cs | 2 +- .../Client/ProxyOperationManager.cs | 6 +----- .../Resources/Resources.Designer.cs | 9 --------- .../Resources/Resources.resx | 3 --- .../Resources/xlf/Resources.cs.xlf | 4 ---- .../Resources/xlf/Resources.de.xlf | 4 ---- .../Resources/xlf/Resources.es.xlf | 4 ---- .../Resources/xlf/Resources.fr.xlf | 4 ---- .../Resources/xlf/Resources.it.xlf | 4 ---- .../Resources/xlf/Resources.ja.xlf | 4 ---- .../Resources/xlf/Resources.ko.xlf | 4 ---- .../Resources/xlf/Resources.pl.xlf | 4 ---- .../Resources/xlf/Resources.pt-BR.xlf | 4 ---- .../Resources/xlf/Resources.ru.xlf | 4 ---- .../Resources/xlf/Resources.tr.xlf | 4 ---- .../Resources/xlf/Resources.xlf | 4 ---- .../Resources/xlf/Resources.zh-Hans.xlf | 4 ---- .../Resources/xlf/Resources.zh-Hant.xlf | 4 ---- .../Client/ProxyExecutionManagerTests.cs | 11 +++++++++++ 19 files changed, 13 insertions(+), 74 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs b/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs index 8148229168..0b5147b771 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/CancellationTokenExtensions.cs @@ -3,8 +3,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Utilities { - using Microsoft.VisualStudio.TestPlatform.ObjectModel; using System.Threading; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; public static class CancellationTokenExtensions { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index e2b9929f49..0a2a83b2f5 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -10,7 +10,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Linq; using System.Reflection; using System.Threading; - using System.Threading.Tasks; using CoreUtilities.Helpers; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; @@ -141,10 +140,7 @@ public virtual bool SetupChannel(IEnumerable sources) { EqtTrace.Error("ProxyOperationManager: Failed to launch testhost :{0}", ex); - if (ex is AggregateException && ex.InnerException is TaskCanceledException) - { - throw new TestPlatformException(Common.Resources.Resources.CancellationRequested); - } + this.CancellationTokenSource.Token.ThrowTestPlatformExceptionIfCancellationRequested(); throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, CrossPlatEngineResources.FailedToLaunchTestHost, ex.ToString())); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs index d585163514..8818823d3c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs @@ -61,15 +61,6 @@ internal Resources() { } } - /// - /// Looks up a localized string similar to Canceling test run as cancelation requested.. - /// - internal static string CancelationRequested { - get { - return ResourceManager.GetString("CancelationRequested", resourceCulture); - } - } - /// /// Looks up a localized string similar to DataCollector debugging is enabled. Please attach debugger to datacollector process to continue.. /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx index bd0cb5da58..c38c31571d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx @@ -177,9 +177,6 @@ No tests matched the filter because it contains one or more properties that are not valid ({0}). Specify filter expression containing valid properties ({1}). - - Canceling test run as cancelation requested. - Failed to launch testhost with error: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf index 165d98c458..1e1072b607 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf @@ -172,10 +172,6 @@ Protokolování diagnostiky TestHost v souboru: {0} - - Canceling test run as cancelation requested. - Testovací běh se na vyžádání ruší. - Failed to launch testhost with error: {0} Nepovedlo se spustit hostitele testu kvůli této chybě: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf index 47efce20e1..4f8097bbf4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf @@ -172,10 +172,6 @@ Die TestHost-Diagnose wird in der Datei {0} protokolliert. - - Canceling test run as cancelation requested. - Der Testlauf wird auf Anforderung hin abgebrochen. - Failed to launch testhost with error: {0} Fehler beim Starten von Testhost: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf index 76f3e2d082..1aff8a2fc0 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf @@ -172,10 +172,6 @@ Registrando diagnóstico de TestHost en el archivo: {0} - - Canceling test run as cancelation requested. - Cancelando la serie de pruebas de acuerdo con la cancelación solicitada. - Failed to launch testhost with error: {0} No se pudo iniciar el host de prueba con el error: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf index f0b0479b20..aad32bbcda 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf @@ -172,10 +172,6 @@ Journalisation des diagnostics TestHost dans le fichier : {0} - - Canceling test run as cancelation requested. - Annulation d'une série de tests en raison d'une demande d'annulation. - Failed to launch testhost with error: {0} Échec du lancement de l'hôte de test. Erreur : {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf index 53c27648f5..f5c87d039e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf @@ -172,10 +172,6 @@ Registrazione della diagnostica di TestHost nel file: {0} - - Canceling test run as cancelation requested. - L'esecuzione dei test verrà annullata perché è stato richiesto l'annullamento. - Failed to launch testhost with error: {0} Non è stato possibile avviare testhost. Errore: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf index 50bc5b659b..839d735d4e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf @@ -172,10 +172,6 @@ 次のファイルで TestHost 診断をログ記録しています: {0} - - Canceling test run as cancelation requested. - 取り消しが要求されたため、テスト実行を取り消しています。 - Failed to launch testhost with error: {0} エラーが発生したため、TestHost を起動できませんでした: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf index ad1d74562c..2e68a325ba 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf @@ -172,10 +172,6 @@ {0} 파일에 TestHost Diagnostics 로깅 중 - - Canceling test run as cancelation requested. - 취소가 요청되어 테스트 실행을 취소합니다. - Failed to launch testhost with error: {0} Testhost를 시작하지 못했습니다(오류: {0}). diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf index 197673c111..976624acbb 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf @@ -172,10 +172,6 @@ Rejestrowanie diagnostyki TestHost w pliku: {0} - - Canceling test run as cancelation requested. - Przebieg testu jest anulowany, ponieważ zażądano anulowania. - Failed to launch testhost with error: {0} Nie można uruchomić hosta testów. Błąd: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf index ea39af7de2..83f5841708 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf @@ -172,10 +172,6 @@ Registro em log do diagnóstico TestHost no arquivo: {0} - - Canceling test run as cancelation requested. - Cancelando a execução de teste como o cancelamento solicitou. - Failed to launch testhost with error: {0} Falha ao iniciar o host de teste com o erro: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf index aef3fab78a..6d4ee3b505 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf @@ -172,10 +172,6 @@ Ведение журналов диагностики TestHost в файле: {0} - - Canceling test run as cancelation requested. - Тестовый запуск отменяется по запросу. - Failed to launch testhost with error: {0} Не удалось запустить хост для тестов с ошибкой: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf index 39d6617b0d..a4ae609b6a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf @@ -172,10 +172,6 @@ TestHost Tanılamaları şu dosyadaki günlüğe kaydediliyor: {0} - - Canceling test run as cancelation requested. - İptal isteğinde bulunulduğundan test çalıştırması iptal ediliyor. - Failed to launch testhost with error: {0} Testhost başlatılamadı. Şu hata alındı: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf index ca71150b8c..82bd189cbd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf @@ -83,10 +83,6 @@ Logging TestHost Diagnostics in file: {0} - - Canceling test run as cancelation requested. - Canceling test run as cancelation requested. - Failed to launch testhost with error: {0} Failed to launch testhost with error: {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf index dab2c9f1b4..e012850b00 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf @@ -172,10 +172,6 @@ 在文件 {0} 中记录 TestHost 诊断 - - Canceling test run as cancelation requested. - 根据取消请求取消测试运行。 - Failed to launch testhost with error: {0} 未能启动测试主机,错误为 {0} diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf index a9fe84fe11..04c681e28e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf @@ -172,10 +172,6 @@ 在檔案 {0} 中記錄 TestHost 診斷 - - Canceling test run as cancelation requested. - 正在依取消的要求而取消測試回合。 - Failed to launch testhost with error: {0} 無法啟動測試主機。錯誤: {0} diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index d0b21f25b0..d96232555c 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -413,6 +413,17 @@ public void StartTestRunForCancelRequestShouldHandleLogMessageWithProperErrorMes mockTestRunEventsHandler.Verify(s => s.HandleLogMessage(TestMessageLevel.Error, "Cancelling the operation as requested.")); } + [TestMethod] + public void StartTestRunForAnExceptionDuringLaunchOfTestShouldHandleLogMessageWithProperErrorMessage() + { + Mock mockTestRunEventsHandler = new Mock(); + this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Throws(new Exception("DummyException")); + + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + mockTestRunEventsHandler.Verify(s => s.HandleLogMessage(TestMessageLevel.Error, It.Is(str => str.StartsWith("Failed to launch testhost with error: System.Exception: DummyException")))); + } + [TestMethod] public void StartTestRunShouldInitiateTestRunForSourcesThroughTheServer() {