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

Enable Trx logger in TPv2 #5

Closed
wants to merge 4 commits into from
Closed
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
43 changes: 36 additions & 7 deletions src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Logging
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
using CommonResources = Microsoft.VisualStudio.TestPlatform.Common.Resources;

/// <summary>
Expand Down Expand Up @@ -52,7 +55,7 @@ internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEvents

private TestLoggerExtensionManager testLoggerExtensionManager;
private IDiscoveryRequest discoveryRequest;

#endregion

#region Constructor
Expand Down Expand Up @@ -157,8 +160,7 @@ public void AddLogger(Uri uri, Dictionary<string, string> parameters)
}
else
{
// todo Read Output Directory from RunSettings
((ITestLogger)logger.Value).Initialize(this.loggerEvents, null);
((ITestLogger)logger.Value).Initialize(this.loggerEvents, this.GetResultsDirectory(RunSettingsManager.Instance.ActiveRunSettings));
}
}
catch (Exception e)
Expand All @@ -181,7 +183,7 @@ public void AddLogger(Uri uri, Dictionary<string, string> parameters)
uri.OriginalString));
}
}

/// <summary>
/// Tries to get uri of the logger corresponding to the friendly name. If no such logger exists return null.
/// </summary>
Expand All @@ -203,7 +205,7 @@ public bool TryGetUriFromFriendlyName(string friendlyName, out string loggerUri)
loggerUri = null;
return false;
}

/// <summary>
/// Registers to receive events from the provided test run request.
/// These events will then be broadcast to any registered loggers.
Expand Down Expand Up @@ -239,7 +241,7 @@ public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest)
this.discoveryRequest = discoveryRequest;
discoveryRequest.OnDiscoveryMessage += this.DiscoveryMessageHandler;
}

/// <summary>
/// Unregisters the events from the test run request.
/// </summary>
Expand All @@ -253,7 +255,7 @@ public void UnregisterTestRunEvents(ITestRunRequest testRunRequest)
testRunRequest.OnRunCompletion -= this.TestRunCompleteHandler;
this.runRequest.DataCollectionMessage -= this.DiscoveryMessageHandler;
}

/// <summary>
/// Unregister the events from the discovery request.
/// </summary>
Expand Down Expand Up @@ -341,6 +343,33 @@ protected virtual void Dispose(bool disposing)

#region Private Members

/// <summary>
/// Gets the test results directory.
/// </summary>
/// <param name="runSettings">Test run settings.</param>
/// <returns>Test results directory</returns>
internal string GetResultsDirectory(RunSettings runSettings)
{
string resultsDirectory = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this just return the default value? Somewhere later I guess we are going to do this. Or are we saying we wont do anything if TestResults directory is not provided?

if (runSettings != null)
{
try
{
RunConfiguration runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings.SettingsXml);
Copy link
Contributor

@AbhitejJohn AbhitejJohn Aug 11, 2016

Choose a reason for hiding this comment

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

RunSettings.GetSettings("RunConfiguration") instead. This is already parsed.

[Faahmad] RunSettings.GetSettings("RunConfiguration") will give you an object of ISettingsProvider. This is not what we want.

Copy link
Contributor

Choose a reason for hiding this comment

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

RunconfigurationSettingsProvider is what you would get. There is a property in RunConfigurationSettingsProvider which gets you the RunConfiguration. You can just add a utility function that does this for you if you want.

resultsDirectory = RunSettingsUtilities.GetTestResultsDirectory(runConfiguration);
}
catch (SettingsException se)
Copy link
Contributor

Choose a reason for hiding this comment

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

When would this be thrown? I'm guessing you dont need this once you change the above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are going through XmlRunSettingsUtilities.GetRunConfigurationNode for now, we can get above exception.

{
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error("TestLoggerManager.GetResultsDirectory: Unable to get the test results directory: Error {0}", se);
}
}
}

return resultsDirectory;
}

/// <summary>
/// Populates user supplied and default logger parameters.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@ public static string GetTestResultsDirectory(RunConfiguration runConfiguration)
string resultsDirectory = null;
if (runConfiguration != null)
{
if (!runConfiguration.ResultsDirectorySet)
{
resultsDirectory = null;
}
else
{
resultsDirectory = Environment.ExpandEnvironmentVariables(runConfiguration.ResultsDirectory);
}
// It will try to get path from runsettings, if not found then it will return default path.
resultsDirectory = Environment.ExpandEnvironmentVariables(runConfiguration.ResultsDirectory);
}

return resultsDirectory;
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
events.TestResult += this.TestResultHandler;
events.TestRunComplete += this.TestRunCompleteHandler;

// ToDo:
// currently we are getting null in testRunDirectory because reading run setting work has to be done
TrxFileDirectory = testRunDirectory;

this.InitializeInternal();
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.ObjectModel/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static class Constants
/// <summary>
/// Default results directory.
/// </summary>
public static readonly string DefaultResultsDirectory = Path.Combine("%Temp%", ResultsDirectoryName);
public static readonly string DefaultResultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), ResultsDirectoryName);

/// <summary>
/// Default treatment of error from test adapters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public string ResultsDirectory
set
{
this.resultsDirectory = value;
this.ResultsDirectorySet = true;
}
}

Expand Down Expand Up @@ -240,15 +239,6 @@ public bool TestAdaptersPathsSet
private set;
}

/// <summary>
/// Gets a value indicating whether results directory is set.
/// </summary>
public bool ResultsDirectorySet
{
get;
private set;
}

/// <summary>
/// Gets the binaries root.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/Microsoft.TestPlatform.VSIXCreator/CopyTrxToExtension.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@IF NOT DEFINED _ECHO @ECHO OFF

@ECHO.

SET TPBINRELPATH=..\\..\\artifacts\\src\\Microsoft.TestPlatform.VSIXCreator\\bin\\Release

IF EXIST "%TPBINRELPATH%" (
IF EXIST "%TPBINRELPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" (
MOVE /Y "%TPBINRELPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" "%TPBINRELPATH%\\net461\\win7-x64\\Extensions"
)
)

SET TPBINDEBUGPATH=..\\..\\artifacts\\src\\Microsoft.TestPlatform.VSIXCreator\\bin\\Debug

IF EXIST "%TPBINDEBUGPATH%" (
IF EXIST "%TPBINDEBUGPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" (
MOVE /Y "%TPBINDEBUGPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" "%TPBINDEBUGPATH%\\net461\\win7-x64\\Extensions"
)
)
10 changes: 5 additions & 5 deletions src/Microsoft.TestPlatform.VSIXCreator/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

"scripts": {
"precompile": "VSIXDelete.cmd",
"postcompile": [ "VSIXCreator.cmd" ]
},
"postcompile": [ "CopyTrxToExtension.cmd", "VSIXCreator.cmd" ]
},

"frameworks": {
"net461": {
Expand All @@ -38,10 +38,10 @@
"testhost": "15.0.0-*",
"testhost.x86": "15.0.0-*",
"vstest.console": "15.0.0-*",

"Microsoft.Internal.TestPlatform.Extensions": {
"type": "build",
"version": "15.0.0"
}
"version": "15.0.0"
},
"Microsoft.TestPlatform.Extensions.TrxLogger": "15.0.0-*"
}
}
2 changes: 1 addition & 1 deletion test/Microsoft.TestPlatform.Client.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.Client": "15.0.0-*"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TestPlatform.Common.UnitTests.Logging
{
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
Expand Down Expand Up @@ -54,6 +55,52 @@ public void TryGetUriFromFriendlyNameShouldNotReturnUriIfLoggerIsNotAdded()
Assert.IsNull(uri);
}

[TestMethod]
public void GetResultsDirectoryShouldReturnNullIfRunSettingsIsNull()
{
string result = TestLoggerManager.Instance.GetResultsDirectory(null);
Assert.AreEqual(null, result);
}

[TestMethod]
public void GetResultsDirectoryShouldReadResultsDirectoryFromSettingsIfSpecified()
{
string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>0</MaxCpuCount>
<ResultsDirectory>DummyTestResultsFolder</ResultsDirectory>
<TargetPlatform> x64 </TargetPlatform>
<TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>
</RunConfiguration>
</RunSettings> ";

RunSettings runsettings = new RunSettings();
runsettings.LoadSettingsXml(runSettingsXml);

string result = TestLoggerManager.Instance.GetResultsDirectory(runsettings);
Assert.AreEqual(string.Compare("DummyTestResultsFolder", result), 0);
}

[TestMethod]
public void GetResultsDirectoryShouldReturnDefaultPathIfResultsDirectoryIsNotProvidedInRunSettings()
{
string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>0</MaxCpuCount>
<TargetPlatform> x64 </TargetPlatform>
<TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>
</RunConfiguration>
</RunSettings> ";

RunSettings runsettings = new RunSettings();
runsettings.LoadSettingsXml(runSettingsXml);

string result = TestLoggerManager.Instance.GetResultsDirectory(runsettings);
Assert.AreEqual(string.Compare(Constants.DefaultResultsDirectory, result), 0);
}

[TestMethod]
public void TestRunRequestRaiseShouldInvokeTestRunMessageHandlerOfLoggersIfRegistered()
{
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.TestPlatform.Common.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.Common": "15.0.0-*"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.CommunicationUtilities": "15.0.0-*"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.CoreUtilities": "15.0.0-*"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.CrossPlatEngine": "15.0.0-*",
"Microsoft.TestPlatform.ObjectModel": "15.0.0-*",
"Microsoft.TestPlatform.Common": "15.0.0-*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.Client": "15.0.0-*",
"Microsoft.TestPlatform.Extensions.TrxLogger": "15.0.0-*",
"Microsoft.TestPlatform.ObjectModel": "15.0.0-*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.ObjectModel": "15.0.0-*"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"Microsoft.TestPlatform.VsTestConsole.TranslationLayer": "15.0.0-*",
"Microsoft.TestPlatform.CommunicationUtilities": "15.0.0-*",
"Microsoft.TestPlatform.ObjectModel": "15.0.0-*"
Expand Down
2 changes: 1 addition & 1 deletion test/datacollector.x86.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"datacollector": "15.0.0-*"
},

Expand Down
2 changes: 1 addition & 1 deletion test/testhost.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015"
"System.Diagnostics.TraceSource": "4.0.0"
},

"frameworks": {
Expand Down
2 changes: 1 addition & 1 deletion test/vstest.console.UnitTests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MSTest.TestFramework": "1.0.0-preview",
"moq.netcore": "4.4.0-beta8",
"System.Diagnostics.TraceSource": "4.0.0-rc2-24015",
"System.Diagnostics.TraceSource": "4.0.0",
"vstest.console": "15.0.0-*",
"Microsoft.TestPlatform.Client": "15.0.0-*"
},
Expand Down