From 781eab0688991e3126a948e1ca92ab383551ac95 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Mon, 18 Dec 2017 16:24:02 +0530 Subject: [PATCH 1/4] Fix for invalid uri in datacollector settings crashing vstest.console --- .../DataCollector/DataCollectorSettings.cs | 10 +++++++++- .../Resources/Resources.Designer.cs | 13 ++++++++++++- .../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 +++++ 17 files changed, 94 insertions(+), 2 deletions(-) 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..656c9e6029 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("InvalidSettingsXmlElement", 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 From 3bce9b21c5d92f2be7e93d80ab165629b059a2f4 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Mon, 18 Dec 2017 18:32:45 +0530 Subject: [PATCH 2/4] Adding the missing changes --- .../Resources/Resources.Designer.cs | 2 +- .../TestPlatformHelpers/TestRequestManager.cs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs index 656c9e6029..faf434cec3 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Resources/Resources.Designer.cs @@ -320,7 +320,7 @@ internal static string InvalidDataCollectorUriInSettings { get { - return ResourceManager.GetString("InvalidSettingsXmlElement", resourceCulture); + return ResourceManager.GetString("InvalidDataCollectorUriInSettings", resourceCulture); } } diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 99554364f7..86dd018fd5 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; From 71315e731b390803c44a01f3777ec5c831b1ee91 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Fri, 22 Dec 2017 18:05:15 +0530 Subject: [PATCH 3/4] Adding the acceptance tests. And fixing the syncing for raised errors not getting logged. --- .../Logging/InternalTestLoggerEvents.cs | 5 +++++ .../Logging/TestLoggerManager.cs | 2 +- .../Processors/Utilities/LoggerUtilities.cs | 4 +++- .../RunsettingsTests.cs | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) 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/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/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs index a394bb5098..5fc5ee5a70 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 + { + { "TestPlaform", "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] From 51b6f84ef773212a1918513176d9acc0cf452863 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Tue, 26 Dec 2017 15:51:53 +0530 Subject: [PATCH 4/4] Fixed the test. --- .../RunsettingsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs index 5fc5ee5a70..728003184c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs @@ -226,7 +226,7 @@ public void RunSettingsWithInvalidValueShouldLogError(RunnerInfo runnerInfo) var runConfigurationDictionary = new Dictionary { - { "TestPlaform", "123" } + { "TargetPlatform", "123" } }; var runsettingsFilePath = this.GetRunsettingsFilePath(runConfigurationDictionary); var arguments = PrepareArguments( @@ -235,7 +235,7 @@ public void RunSettingsWithInvalidValueShouldLogError(RunnerInfo runnerInfo) 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'."); + 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); }