diff --git a/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs b/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs index e3ac5fcaa3..256f3111a3 100644 --- a/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs +++ b/src/Microsoft.TestPlatform.Common/Logging/InternalTestLoggerEvents.cs @@ -186,6 +186,11 @@ internal void RaiseTestRunMessage(TestRunMessageEventArgs args) this.SafeInvokeAsync(() => this.TestRunMessage, args, 0, "InternalTestLoggerEvents.SendTestRunMessage"); } + internal void WaitForEventCompletion() + { + this.loggerEventQueue.Flush(); + } + /// /// Raises a test result event to the enabled loggers. /// diff --git a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs index d5f166b5f2..54e89df977 100644 --- a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs +++ b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs @@ -110,7 +110,7 @@ protected set /// /// Gets the logger events. /// - public TestLoggerEvents LoggerEvents + public InternalTestLoggerEvents LoggerEvents { get { diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs index 277a86542f..df50008fc7 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs @@ -160,7 +160,15 @@ internal static DataCollectorSettings FromXml(XmlReader reader) { case "uri": ValidateArg.NotNullOrEmpty(reader.Value, "uri"); - settings.Uri = new Uri(reader.Value); + try + { + settings.Uri = new Uri(reader.Value); + } + catch (UriFormatException) + { + throw new SettingsException(String.Format(CultureInfo.CurrentCulture, Resources.Resources.InvalidDataCollectorUriInSettings, reader.Value)); + } + break; case "assemblyQualifiedName": diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs index d729dffa26..faf434cec3 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs @@ -312,7 +312,18 @@ internal static string InvalidSettingsXmlElement { return ResourceManager.GetString("InvalidSettingsXmlElement", resourceCulture); } } - + + /// + /// Looks up a localized string similar to Invalid URI in data collector settings '{0}'.. + /// + internal static string InvalidDataCollectorUriInSettings + { + get + { + return ResourceManager.GetString("InvalidDataCollectorUriInSettings", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid data collector settings. Expected attribute '{0}' is missing. A typical data collector setting would look like <DataCollector uri="dataCollector://Samples/SampleCollector/1.0" assemblyQualifiedName="Samples.SampleCollector.SampleDataCollector, SampleCollectors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111" friendlyName="sampleCollector">.. /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.resx b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.resx index 35f3531d7b..2537968a90 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.resx @@ -335,4 +335,7 @@ Failed to load msdia + + Invalid URI in data collector settings '{0}'. + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.cs.xlf index e52ba4676e..d45b365ff9 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.cs.xlf @@ -597,6 +597,11 @@ Nepovedlo se načíst knihovnu msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.de.xlf index b5ff98cea6..be2c6af911 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.de.xlf @@ -597,6 +597,11 @@ Fehler beim Laden von MSDIA. + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.es.xlf index dc1786677f..ba71a225b9 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.es.xlf @@ -597,6 +597,11 @@ No se pudo cargar msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.fr.xlf index c0c8f9493d..1ce0ff51c4 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.fr.xlf @@ -597,6 +597,11 @@ Échec du chargement de msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.it.xlf index 8cfa1ca70b..885a93dacd 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.it.xlf @@ -597,6 +597,11 @@ Non è stato possibile caricare msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ja.xlf index 566ddfeddf..1cb09c3d39 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ja.xlf @@ -597,6 +597,11 @@ msdia を読み込めませんでした + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ko.xlf index 2c1acc14f5..98cd6a7439 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ko.xlf @@ -597,6 +597,11 @@ msdia 로드 실패 + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pl.xlf index 401d99cbe1..183471b5fe 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pl.xlf @@ -597,6 +597,11 @@ Nie można załadować elementu msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pt-BR.xlf index 610cdb13e1..a448582a0a 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.pt-BR.xlf @@ -597,6 +597,11 @@ Falha ao carregar msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ru.xlf index 7c6b572b13..903e011a5a 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.ru.xlf @@ -597,6 +597,11 @@ Не удалось загрузить msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.tr.xlf index 68098617a4..6529a2747d 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.tr.xlf @@ -597,6 +597,11 @@ Msdia yüklenemedi + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.xlf index e3971a9e46..6904bb5cb4 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.xlf @@ -263,6 +263,11 @@ Failed to load msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hans.xlf index c5af18ec11..3562440718 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hans.xlf @@ -597,6 +597,11 @@ 未能加载 msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hant.xlf index e05abc53ef..43f79587c4 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/xlf/Resources.zh-Hant.xlf @@ -597,6 +597,11 @@ 無法載入 msdia + + Invalid URI in data collector settings '{0}'. + Invalid URI in data collector settings '{0}'. + + \ No newline at end of file diff --git a/src/vstest.console/Processors/Utilities/LoggerUtilities.cs b/src/vstest.console/Processors/Utilities/LoggerUtilities.cs index 338e989ab1..d03c599c90 100644 --- a/src/vstest.console/Processors/Utilities/LoggerUtilities.cs +++ b/src/vstest.console/Processors/Utilities/LoggerUtilities.cs @@ -27,6 +27,8 @@ internal static void RaiseTestRunError(TestLoggerManager loggerManager, TestRunR errorMessage = new TestRunMessageEventArgs(TestMessageLevel.Error, exception.InnerException.Message); loggerManager.SendTestRunMessage(errorMessage); } + + loggerManager.LoggerEvents.WaitForEventCompletion(); } internal static void RaiseTestRunWarning(TestLoggerManager loggerManager, TestRunResultAggregator testRunResultAggregator, string warningMessage) @@ -34,7 +36,7 @@ internal static void RaiseTestRunWarning(TestLoggerManager loggerManager, TestRu TestRunMessageEventArgs testRunMessage = new TestRunMessageEventArgs(TestMessageLevel.Warning, warningMessage); loggerManager.SendTestRunMessage(testRunMessage); } - + /// /// Parses the parameters passed as name values pairs along with the logger argument. /// diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index a862afc596..bcf844ad99 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -507,12 +507,15 @@ ex is SettingsException || } finally { - this.testLoggerManager.UnregisterTestRunEvents(this.currentTestRunRequest); - this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); - testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); + if (this.currentTestRunRequest != null) + { + this.testLoggerManager.UnregisterTestRunEvents(this.currentTestRunRequest); + this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); + testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); - this.currentTestRunRequest.Dispose(); - this.currentTestRunRequest = null; + this.currentTestRunRequest.Dispose(); + this.currentTestRunRequest = null; + } } return success; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs index a394bb5098..728003184c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs @@ -217,6 +217,28 @@ public void RunSettingsWithParallelAndPlatformX64(RunnerInfo runnerInfo) this.RunTestWithRunSettings(runConfigurationDictionary, null, null, testhostProcessName, expectedProcessCreated); } + [CustomDataTestMethod] + [NETFullTargetFramework(inIsolation: true, inProcess: true)] + [NETCORETargetFramework] + public void RunSettingsWithInvalidValueShouldLogError(RunnerInfo runnerInfo) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); + + var runConfigurationDictionary = new Dictionary + { + { "TargetPlatform", "123" } + }; + var runsettingsFilePath = this.GetRunsettingsFilePath(runConfigurationDictionary); + var arguments = PrepareArguments( + this.GetSampleTestAssembly(), + string.Empty, + runsettingsFilePath, + runnerInfo.InIsolationValue); + this.InvokeVsTest(arguments); + this.StdErrorContains(@"Settings file provided does not conform to required format. An error occurred while loading the settings. Error: Invalid setting 'RunConfiguration'. Invalid value '123' specified for 'TargetPlatform'."); + File.Delete(runsettingsFilePath); + } + [CustomDataTestMethod] [NETFullTargetFramework(inIsolation: true, inProcess: true)] [NETCORETargetFramework]