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

Logger support in run settings #1382

Merged
merged 15 commits into from
Jan 30, 2018

Conversation

abhishekkumawat23
Copy link
Contributor

@abhishekkumawat23 abhishekkumawat23 commented Jan 22, 2018

Description

Contains following changes:

  1. Loggers information from RunSettings
  2. Logger support enabled for design mode

RFC PR

microsoft/vstest-docs#111

@@ -210,7 +196,7 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove
ex is SettingsException ||
ex is InvalidOperationException)
{
LoggerUtilities.RaiseTestRunError(testLoggerManager, null, ex);
ConsoleLogger.RaiseTestRunError(null, ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConsoleLogger.RaiseTestRunError(null, ex); [](start = 20, length = 42)

nitpick: can we move this closer to the logger initialization code alone..?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that logger initialization is happening within this block only.

@@ -296,6 +296,13 @@ public static void UpdateTargetPlatform(XmlDocument runSettingsDocument, string
AddNodeIfNotPresent<string>(runSettingsDocument, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite);
}

public static void UpdateLoggerRunSettings(XmlDocument xmlDocument, string loggerRunSettings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not reqd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings();
var existingLoggerIndex = LoggerUtilities.GetExistingLoggerIndex(ConsoleLogger.FriendlyName, new Uri(ConsoleLogger.ExtensionUri),
loggerRunSettings.LoggerSettingsList);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: loggerRunSettings.GetExistingLoggerIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@abhishkk abhishkk changed the title [In Progress] Logger in run settings u1 Logger support in run settings Jan 29, 2018
@@ -37,5 +37,7 @@ public interface ITestEngine
/// </summary>
/// <returns>ITestExtensionManager object that helps with extensibility</returns>
ITestExtensionManager GetExtensionManager();

ITestLoggerManager GetLoggerManager(IRequestData requestData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// <summary>
/// Dispose logger manager.
/// </summary>
void Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDisposable instead.

/// </summary>
public const string LoggerSettingName = "Logger";

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't similar consts defined for datacollector already ?

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

// ReSharper disable CheckNamespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

};
}

// Converting logger cosole params to Configuration element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: console

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -199,6 +243,18 @@ private static void HandleInvalidArgument(string argument)
argument));
}

/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, prefer InheritDoc instead of generic docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

this.testLoggerManager = new TestableTestLoggerManager();
this.testLoggerManager.AddLogger(this.blameLogger, BlameLogger.ExtensionUri, null);
this.testLoggerManager.EnableLogging();
// this.testLoggerManager = new TestableTestLoggerManager();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable these please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -166,10 +166,10 @@
<value>Error: Invalid operator '{0}'</value>
</data>
<data name="LoggerInitializationError" xml:space="preserve">
<value>Exception occurred while initializing logger with URI '{0}'. The logger will not be used. Exception: {1}</value>
<value>Exception occurred while initializing logger with {0}: '{1}'. The logger will not be used. Exception: {2}</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run build.cmd, then add the other lang changes as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// <param name="friendlyName"></param>
/// <param name="uri"></param>
/// <param name="loggerSettingsList"></param>
/// <returns></returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review docs

this.mockOutput.Verify(o => o.WriteLine("Error123", OutputLevel.Error), Times.Once());
// this.mockOutput.Verify(o => o.WriteLine("Informational123", OutputLevel.Information), Times.Once());
// this.mockOutput.Verify(o => o.WriteLine("Warning123", OutputLevel.Warning), Times.Once());
// this.mockOutput.Verify(o => o.WriteLine("Error123", OutputLevel.Error), Times.Once());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this?

// Assert.ThrowsException<NullReferenceException>(() =>
// {
// testRunRequest.Raise(m => m.OnRunStatsChange += null, eventarg);
// });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
// this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
// this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

/// <returns>ITestLoggerManager object that helps with logger extensibility.</returns>
public ITestLoggerManager GetLoggerManager(IRequestData requestData)
{
return new TestLoggerManager(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate the data in IRequestData is getting logged properly, even after the request is complete.

Copy link
Contributor

@singhsarab singhsarab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with suggestions

@@ -296,6 +296,13 @@ public static void UpdateTargetPlatform(XmlDocument runSettingsDocument, string
AddNodeIfNotPresent<string>(runSettingsDocument, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite);
}

public static void UpdateLoggerRunSettings(XmlDocument xmlDocument, string loggerRunSettings)
{
// TODO: No need for entry here. move to testrequestmanager.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not required

{
if (configurationElement == null)
{
// There is no configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required here

// Add the logger and if it is a non-existent logger, throw.
var loggerType =
assembly?.GetTypes()
.FirstOrDefault(x => x.AssemblyQualifiedName.Equals(assemblyQualifiedName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put inside try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -45,6 +45,12 @@ public static void AddDefaultRunSettings(this IRunSettingsProvider runSettingsPr
runSettingsProvider.UpdateRunSettings(runSettingsXml);
}

public static void UpdateRunSettingsXmlDocumentInnerXml(XmlDocument xmlDocument, string key, string data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its required.

Copy link
Contributor

@acesiddhu acesiddhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@abhishkk
Copy link
Contributor

abhishkk commented Jan 30, 2018

Validated all scenarios and resolved pr comments.
Scenarios validated:

  1. Logger is respected from runsettings.
  2. If same logger multiple times, first is respected.
  3. If same logger is present both in command line and runsettings, command line is respected.
  4. If design mode is false, console logger is added automatically.
  5. if design mode is false and console logger is present in runsettings, existing console logger params are used but assemblyQualifiedName is updated.
  6. Console logger params like verbosity is working fine.
  7. Among uri, assemblyQualifiedName and friendlyName, priority order is assemblyQualifiedName > uri > friendlyName
  8. Exception thrown on invalid xml, invalid attributes, invalid node in runsettings.
  9. Exception thrown if unable to initialize logger.
  10. EqtTrace, Logs are logged for appropriate scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants