Skip to content

Commit

Permalink
Support for dotnet core deps files (#71)
Browse files Browse the repository at this point in the history
* WIP: Extract a test host manager for dotnet core.
* WIP: Add tests for dotnet test host manager.
* WIP: Minor test fixes.
* Remove rc2 dependencies on system components.
* Add nuget package for TestPlatform.TestHost.
For .net core based test projects, test host will be a runtime dependency.
* Add NoPackageAnalysis for TestPlatform.CLI package.
* Move few more packages to dotnet dependencies with .netcoreapp1.0 support.
* Use assembly.load for discovery of test plugins across platforms. Escape paths for runtimeconfig and deps.
* Refactor ITestHostManager.
* Introduce a Shared property in TestHostManager to indicate if a test host can be shared across test sources.
* Minor fix to take parent directory for test engine location.
  • Loading branch information
codito authored Sep 23, 2016
1 parent 3766e5c commit 4f34968
Show file tree
Hide file tree
Showing 64 changed files with 1,685 additions and 1,050 deletions.
8 changes: 5 additions & 3 deletions dogfood/UnitTestProject/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
"dnxcore50",
"portable-net45+win8"
],

"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
},

"net46": {
"frameworkAssemblies": {
"System.Runtime": ""
}
"frameworkAssemblies": {
"System.Runtime": ""
}
}
}
}
13 changes: 10 additions & 3 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ function Create-NugetPackages
$tpSrcDir = Join-Path $env:TP_ROOT_DIR "src"

# Copy over the nuspecs to the staging directory
$nuspecFiles = @("TestPlatform.TranslationLayer.nuspec", "TestPlatform.ObjectModel.nuspec", "TestPlatform.nuspec", "TestPlatform.CLI.nuspec")
$nuspecFiles = @("TestPlatform.TranslationLayer.nuspec", "TestPlatform.ObjectModel.nuspec", "TestPlatform.TestHost.nuspec", "TestPlatform.nuspec", "TestPlatform.CLI.nuspec")
# Nuget pack analysis emits warnings if binaries are packaged as content. It is intentional for the below packages.
$skipAnalysis = @("TestPlatform.CLI.nuspec")
foreach ($file in $nuspecFiles) {
Copy-Item $tpSrcDir\$file $stagingDir -Force
}
Expand All @@ -255,8 +257,13 @@ function Create-NugetPackages
$nugetExe = Join-Path $env:TP_PACKAGES_DIR -ChildPath "Nuget.CommandLine" | Join-Path -ChildPath $env:NUGET_EXE_Version | Join-Path -ChildPath "tools\NuGet.exe"

foreach ($file in $nuspecFiles) {
Write-Verbose "$nugetExe pack $stagingDir\$file -OutputDirectory $stagingDir"
& $nugetExe pack $stagingDir\$file -OutputDirectory $stagingDir
$additionalArgs = ""
if ($skipAnalysis -contains $file) {
$additionalArgs = "-NoPackageAnalysis"
}

Write-Verbose "$nugetExe pack $stagingDir\$file -OutputDirectory $stagingDir $additionalArgs"
& $nugetExe pack $stagingDir\$file -OutputDirectory $stagingDir $additionalArgs
}

Write-Log "Create-NugetPackages: Complete. {$(Get-ElapsedTime($timer))}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
{
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;

/// <summary>
/// DesignMode TestHost Launcher for hosting of test process
/// </summary>
internal class DesignModeTestHostLauncher : ITestHostLauncher
{
private IDesignModeClient designModeClient;
private readonly IDesignModeClient designModeClient;

/// <summary>
/// Initializes a new instance of the <see cref="DesignModeTestHostLauncher"/> class.
/// </summary>
/// <param name="designModeClient">Design mode client instance.</param>
public DesignModeTestHostLauncher(IDesignModeClient designModeClient)
{
this.designModeClient = designModeClient;
}

/// <inheritdoc/>
public virtual bool IsDebug => false;

/// <inheritdoc/>
public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
{
return this.designModeClient.LaunchCustomHost(defaultTestHostStartInfo);
Expand All @@ -34,10 +36,12 @@ public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
/// </summary>
internal class DesignModeDebugTestHostLauncher : DesignModeTestHostLauncher
{
/// <inheritdoc/>
public DesignModeDebugTestHostLauncher(IDesignModeClient designModeClient) : base(designModeClient)
{
}

/// <inheritdoc/>
public override bool IsDebug => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
{
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

/// <summary>
/// Factory for providing the design mode test host launchers
Expand All @@ -21,7 +17,7 @@ public static class DesignModeTestHostLauncherFactory
public static ITestHostLauncher GetCustomHostLauncherForTestRun(IDesignModeClient designModeClient, TestRunRequestPayload testRunRequestPayload)
{
ITestHostLauncher testHostLauncher = null;
if(!testRunRequestPayload.DebuggingEnabled)
if (!testRunRequestPayload.DebuggingEnabled)
{
testHostLauncher = defaultLauncher = defaultLauncher ?? new DesignModeTestHostLauncher(designModeClient);
}
Expand Down
79 changes: 38 additions & 41 deletions src/Microsoft.TestPlatform.Client/Discovery/DiscoveryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.Discovery

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.Utilities;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

/// <summary>
/// The discovery request.
/// </summary>
Expand All @@ -22,8 +21,8 @@ public sealed class DiscoveryRequest : IDiscoveryRequest, ITestDiscoveryEventsHa
/// <summary>
/// Initializes a new instance of the <see cref="DiscoveryRequest"/> class.
/// </summary>
/// <param name="criteria"> The criteria. </param>
/// <param name="discoveryManager"> The discovery manager. </param>
/// <param name="criteria">Discovery criterion.</param>
/// <param name="discoveryManager">Discovery manager instance.</param>
internal DiscoveryRequest(DiscoveryCriteria criteria, IProxyDiscoveryManager discoveryManager)
{
this.DiscoveryCriteria = criteria;
Expand All @@ -42,7 +41,7 @@ void IDiscoveryRequest.DiscoverAsync()

lock (this.syncObject)
{
if (this.bDisposed)
if (this.disposed)
{
throw new ObjectDisposedException("DiscoveryRequest");
}
Expand Down Expand Up @@ -80,7 +79,7 @@ void IDiscoveryRequest.Abort()

lock (this.syncObject)
{
if (this.bDisposed)
if (this.disposed)
{
throw new ObjectDisposedException("DiscoveryRequest");
}
Expand All @@ -95,6 +94,7 @@ void IDiscoveryRequest.Abort()
{
EqtTrace.Info("DiscoveryRequest.Abort: No operation to abort.");
}

return;
}
}
Expand All @@ -116,7 +116,7 @@ bool IRequest.WaitForCompletion(int timeout)
EqtTrace.Verbose("DiscoveryRequest.WaitForCompletion: Waiting with timeout {0}.", timeout);
}

if (this.bDisposed)
if (this.disposed)
{
throw new ObjectDisposedException("DiscoveryRequest");
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public DiscoveryCriteria DiscoveryCriteria
/// </summary>
internal bool DiscoveryInProgress
{
get { return discoveryInProgress; }
get { return this.discoveryInProgress; }
}

/// <summary>
Expand All @@ -179,47 +179,48 @@ internal bool DiscoveryInProgress

#region ITestDiscoveryEventsHandler Methods

/// <summary>
/// Dispatch DiscoveryComplete event to listeners.
/// </summary>
/// <inheritdoc/>
public void HandleDiscoveryComplete(long totalTests, IEnumerable<TestCase> lastChunk, bool isAborted)
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("DiscoveryRequest.DiscoveryComplete: Starting. Aborted:{0}, TotalTests:{1}", isAborted, totalTests);
}

lock (this.syncObject)
{
if (this.bDisposed)
if (this.disposed)
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning("DiscoveryRequest.DiscoveryComplete: Ignoring as the object is disposed.");
}

return;
}
//If discovery event is already raised, ignore current one.

// If discovery event is already raised, ignore current one.
if (this.discoveryCompleted.WaitOne(0))
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("DiscoveryRequest.DiscoveryComplete:Ignoring duplicate DiscoveryComplete. Aborted:{0}, TotalTests:{1}", isAborted, totalTests);
}

return;
}

try
{
// Raise onDiscoveredTests event if there are some tests in the last chunk.
//
// (We dont want to send the tests in the discovery complete event so that programming on top of
// RS client is easier i.e. user does not have to listen on discovery complete event.)
// RS client is easier i.e. user does not have to listen on discovery complete event.)
if (lastChunk != null && lastChunk.Count() > 0)
{
OnDiscoveredTests.SafeInvoke(this, new DiscoveredTestsEventArgs(lastChunk), "DiscoveryRequest.DiscoveryComplete");
this.OnDiscoveredTests.SafeInvoke(this, new DiscoveredTestsEventArgs(lastChunk), "DiscoveryRequest.DiscoveryComplete");
}

OnDiscoveryComplete.SafeInvoke(this, new DiscoveryCompleteEventArgs(totalTests, isAborted), "DiscoveryRequest.DiscoveryComplete");
this.OnDiscoveryComplete.SafeInvoke(this, new DiscoveryCompleteEventArgs(totalTests, isAborted), "DiscoveryRequest.DiscoveryComplete");
}
finally
{
Expand All @@ -241,6 +242,7 @@ public void HandleDiscoveryComplete(long totalTests, IEnumerable<TestCase> lastC
EqtTrace.Warning("DiscoveryRequest.DiscoveryComplete: Discovery complete event was null.");
}
}

this.discoveryInProgress = false;
}
}
Expand All @@ -251,11 +253,7 @@ public void HandleDiscoveryComplete(long totalTests, IEnumerable<TestCase> lastC
}
}

/// <summary>
/// Dispatch DiscoveredTest event to listeners.
/// </summary>
/// <param name="discoveryManager">Instance of IDiscoveryManager that discovered tests.</param>
/// <param name="discoveredTestCases">Discovered test cases.</param>
/// <inheritdoc/>
public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)
{
if (EqtTrace.IsVerboseEnabled)
Expand All @@ -265,17 +263,19 @@ public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)

lock (this.syncObject)
{
if (this.bDisposed)
if (this.disposed)
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning("DiscoveryRequest.SendDiscoveredTests: Ignoring as the object is disposed.");
}

return;
}

OnDiscoveredTests.SafeInvoke(this, new DiscoveredTestsEventArgs(discoveredTestCases), "DiscoveryRequest.OnDiscoveredTests");
this.OnDiscoveredTests.SafeInvoke(this, new DiscoveredTestsEventArgs(discoveredTestCases), "DiscoveryRequest.OnDiscoveredTests");
}

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("DiscoveryRequest.SendDiscoveredTests: Completed.");
Expand All @@ -285,8 +285,7 @@ public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)
/// <summary>
/// Dispatch TestRunMessage event to listeners.
/// </summary>
/// <param name="discoveryManager">Instnace of IDiscoveryManager that discovered tests</param>
/// <param name="level">Ouput level of the message being sent.</param>
/// <param name="level">Output level of the message being sent.</param>
/// <param name="message">Actual contents of the message</param>
public void HandleLogMessage(TestMessageLevel level, string message)
{
Expand All @@ -297,16 +296,17 @@ public void HandleLogMessage(TestMessageLevel level, string message)

lock (this.syncObject)
{
if (this.bDisposed)
if (this.disposed)
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning("DiscoveryRequest.SendDiscoveryMessage: Ignoring as the object is disposed.");
}

return;
}

OnDiscoveryMessage.SafeInvoke(this, new TestRunMessageEventArgs(level, message), "DiscoveryRequest.OnTestMessageRecieved");
this.OnDiscoveryMessage.SafeInvoke(this, new TestRunMessageEventArgs(level, message), "DiscoveryRequest.OnTestMessageRecieved");
}

if (EqtTrace.IsInfoEnabled)
Expand All @@ -318,7 +318,7 @@ public void HandleLogMessage(TestMessageLevel level, string message)
/// <summary>
/// Handle Raw message directly from the host
/// </summary>
/// <param name="rawMessage"></param>
/// <param name="rawMessage">Raw message.</param>
public void HandleRawMessage(string rawMessage)
{
this.OnRawMessageReceived?.Invoke(this, rawMessage);
Expand All @@ -328,20 +328,17 @@ public void HandleRawMessage(string rawMessage)

#region IDisposable implementation

// Summary:
// Performs application-defined tasks associated with freeing, releasing, or
// resetting unmanaged resources.
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
this.Dispose(true);

GC.SuppressFinalize(this);
}

/// <summary>
/// Dispose the discovery request.
/// </summary>
/// <param name="disposing"></param>
private void Dispose(bool disposing)
{
if (EqtTrace.IsVerboseEnabled)
Expand All @@ -351,7 +348,7 @@ private void Dispose(bool disposing)

lock (this.syncObject)
{
if (!this.bDisposed)
if (!this.disposed)
{
if (disposing)
{
Expand All @@ -363,7 +360,7 @@ private void Dispose(bool disposing)

// Indicate that object has been disposed
this.discoveryCompleted = null;
this.bDisposed = true;
this.disposed = true;
}
}

Expand All @@ -380,7 +377,7 @@ private void Dispose(bool disposing)
/// <summary>
/// If this request has been disposed.
/// </summary>
private bool bDisposed = false;
private bool disposed = false;

/// <summary>
/// It get set when current discovery request is completed.
Expand All @@ -390,7 +387,7 @@ private void Dispose(bool disposing)
/// <summary>
/// Sync object for various operations
/// </summary>
private Object syncObject = new Object();
private object syncObject = new Object();

/// <summary>
/// Whether or not the test discovery is in progress.
Expand Down
Loading

0 comments on commit 4f34968

Please sign in to comment.