Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the crash scenario for Invalid runsettings #1344

Merged
merged 6 commits into from
Dec 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ internal void RaiseTestRunMessage(TestRunMessageEventArgs args)
this.SafeInvokeAsync(() => this.TestRunMessage, args, 0, "InternalTestLoggerEvents.SendTestRunMessage");
}

internal void WaitForEventCompletion()
{
this.loggerEventQueue.Flush();
}

/// <summary>
/// Raises a test result event to the enabled loggers.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected set
/// <summary>
/// Gets the logger events.
/// </summary>
public TestLoggerEvents LoggerEvents
public InternalTestLoggerEvents LoggerEvents
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,7 @@
<data name="FailedToLoadMsDia" xml:space="preserve">
<value>Failed to load msdia</value>
</data>
<data name="InvalidDataCollectorUriInSettings" xml:space="preserve">
<value>Invalid URI in data collector settings '{0}'.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Nepovedlo se načíst knihovnu msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Fehler beim Laden von MSDIA.</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">No se pudo cargar msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Échec du chargement de msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Non è stato possibile caricare msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">msdia を読み込めませんでした</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">msdia 로드 실패</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Nie można załadować elementu msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Falha ao carregar msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Не удалось загрузить msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">Msdia yüklenemedi</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@
<target state="new">Failed to load msdia</target>
<note></note>
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">未能加载 msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@
<target state="translated">無法載入 msdia</target>
<note />
</trans-unit>
<trans-unit id="InvalidDataCollectorUriInSettings">
<source>Invalid URI in data collector settings '{0}'.</source>
<target state="new">Invalid URI in data collector settings '{0}'.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 3 additions & 1 deletion src/vstest.console/Processors/Utilities/LoggerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ 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)
{
TestRunMessageEventArgs testRunMessage = new TestRunMessageEventArgs(TestMessageLevel.Warning, warningMessage);
loggerManager.SendTestRunMessage(testRunMessage);
}

/// <summary>
/// Parses the parameters passed as name values pairs along with the logger argument.
/// </summary>
Expand Down
13 changes: 8 additions & 5 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
{
{ "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]
Expand Down