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 2 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
48 changes: 41 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 ObjectModel.Utilities;
Copy link
Contributor

Choose a reason for hiding this comment

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

use full namespace.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using 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, 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,38 @@ 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>
private static string GetResultsDirectory(RunSettings runSettings)
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.

why is this a static?

[faahmad] No need of static, fixed in next commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unit tests please?

Copy link
Contributor Author

@Faizan2304 Faizan2304 Aug 11, 2016

Choose a reason for hiding this comment

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

Added test in next commit.

{
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);
}
}
}

if (string.IsNullOrEmpty(resultsDirectory))
{
resultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), Constants.ResultsDirectoryName);
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.

There are two defaults for resultsdirectory - one pointing to %temp% and the other to GetCurrentDirectory(). We should just have one.
[Faahmad] fixed

}

return resultsDirectory;
}

/// <summary>
/// Populates user supplied and default logger parameters.
/// </summary>
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
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-*"
}
}