-
Notifications
You must be signed in to change notification settings - Fork 325
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
Run NetFramework tests inside vstest.console.exe process #1009
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e98195a
No isolation discovery for net46 with design mode off
ddb91be
NoIsolation test run for net46
bfb18d6
Merge branch 'master' into noIsolation
Faizan2304 a881a1a
Make api asynchronous
Faizan2304 a2a391d
Merge branch 'master' into noIsolation
ede0e04
1) Renamed argument processor to InProcess
2f76f3c
1) Making in process default for net46
d1237cd
Merge branch 'master' into noIsolation
172f9d0
Disable inprocess for inProcDataCollector.
39c40c2
Addressed Arun comment
ed5a9ca
Append comment
4124fde
Merge branch 'master' into noIsolation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/Microsoft.TestPlatform.CrossPlatEngine/Client/InProcessProxyDiscoveryManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
|
||
internal class InProcessProxyDiscoveryManager : IProxyDiscoveryManager | ||
{ | ||
private ITestHostManagerFactory testHostManagerFactory; | ||
private IDiscoveryManager discoveryManager; | ||
private ITestRuntimeProvider testHostManager; | ||
public bool IsInitialized { get; private set; } = false; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InProcessProxyDiscoveryManager"/> class. | ||
/// </summary> | ||
public InProcessProxyDiscoveryManager(ITestRuntimeProvider testHostManager) : this(testHostManager, new TestHostManagerFactory()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InProcessProxyDiscoveryManager"/> class. | ||
/// </summary> | ||
/// <param name="testHostManagerFactory">Manager factory</param> | ||
internal InProcessProxyDiscoveryManager(ITestRuntimeProvider testHostManager, ITestHostManagerFactory testHostManagerFactory) | ||
{ | ||
this.testHostManager = testHostManager; | ||
this.testHostManagerFactory = testHostManagerFactory; | ||
this.discoveryManager = this.testHostManagerFactory.GetDiscoveryManager(); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes test discovery. | ||
/// </summary> | ||
public void Initialize() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Discovers tests | ||
/// </summary> | ||
/// <param name="discoveryCriteria">Settings, parameters for the discovery request</param> | ||
/// <param name="eventHandler">EventHandler for handling discovery events from Engine</param> | ||
public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler eventHandler) | ||
{ | ||
Task.Run(() => | ||
{ | ||
try | ||
{ | ||
// Initialize extension before discovery | ||
this.InitializeExtensions(discoveryCriteria.Sources); | ||
this.discoveryManager.DiscoverTests(discoveryCriteria, eventHandler); | ||
} | ||
catch (Exception exception) | ||
{ | ||
EqtTrace.Error("InProcessProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception); | ||
|
||
// Send a discovery complete to caller. | ||
eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.ToString()); | ||
eventHandler.HandleDiscoveryComplete(-1, Enumerable.Empty<TestCase>(), true); | ||
} | ||
} | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Closes the current test operation. | ||
/// This function is of no use in this context as we are not creating any testhost | ||
/// </summary> | ||
public void Close() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Aborts the test operation. | ||
/// </summary> | ||
public void Abort() | ||
{ | ||
Task.Run(() => this.testHostManagerFactory.GetDiscoveryManager().Abort()); | ||
} | ||
|
||
private void InitializeExtensions(IEnumerable<string> sources) | ||
{ | ||
var extensionsFromSource = this.testHostManager.GetTestPlatformExtensions(sources, Enumerable.Empty<string>()); | ||
if (extensionsFromSource.Any()) | ||
{ | ||
TestPluginCache.Instance.UpdateExtensions(extensionsFromSource, false); | ||
} | ||
|
||
// We don't need to pass list of extension as we are running inside vstest.console and | ||
// it will use TestPluginCache of vstest.console | ||
discoveryManager.Initialize(Enumerable.Empty<string>()); | ||
} | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
src/Microsoft.TestPlatform.CrossPlatEngine/Client/InProcessProxyexecutionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.TesthostProtocol; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; | ||
|
||
internal class InProcessProxyExecutionManager : IProxyExecutionManager | ||
{ | ||
private ITestHostManagerFactory testHostManagerFactory; | ||
private IExecutionManager executionManager; | ||
private ITestRuntimeProvider testHostManager; | ||
public bool IsInitialized { get; private set; } = false; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InProcessProxyexecutionManager"/> class. | ||
/// </summary> | ||
public InProcessProxyExecutionManager(ITestRuntimeProvider testHostManager) : this(testHostManager, new TestHostManagerFactory()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InProcessProxyexecutionManager"/> class. | ||
/// </summary> | ||
/// <param name="testHostManagerFactory"> | ||
/// Manager factory | ||
/// </param> | ||
internal InProcessProxyExecutionManager(ITestRuntimeProvider testHostManager, ITestHostManagerFactory testHostManagerFactory) | ||
{ | ||
this.testHostManager = testHostManager; | ||
this.testHostManagerFactory = testHostManagerFactory; | ||
this.executionManager = this.testHostManagerFactory.GetExecutionManager(); | ||
} | ||
|
||
/// <summary> | ||
/// Initialize adapters. | ||
/// </summary> | ||
public void Initialize() | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler) | ||
{ | ||
try | ||
{ | ||
// This code should be in sync with ProxyExecutionManager.StartTestRun executionContext | ||
var executionContext = new TestExecutionContext( | ||
testRunCriteria.FrequencyOfRunStatsChangeEvent, | ||
testRunCriteria.RunStatsChangeEventTimeout, | ||
inIsolation: false, | ||
keepAlive: testRunCriteria.KeepAlive, | ||
isDataCollectionEnabled: false, | ||
areTestCaseLevelEventsRequired: false, | ||
hasTestRun: true, | ||
isDebug: (testRunCriteria.TestHostLauncher != null && testRunCriteria.TestHostLauncher.IsDebug), | ||
testCaseFilter: testRunCriteria.TestCaseFilter); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should ask TestRuntimeProvider for extensions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should. |
||
|
||
if (testRunCriteria.HasSpecificSources) | ||
{ | ||
// Initialize extension before execution | ||
this.InitializeExtensions(testRunCriteria.Sources); | ||
|
||
Task.Run(() => executionManager.StartTestRun(testRunCriteria.AdapterSourceMap, testRunCriteria.TestRunSettings, executionContext, null, eventHandler)); | ||
} | ||
else | ||
{ | ||
// If the test execution is with a test filter, group them by sources | ||
var testSources = testRunCriteria.Tests.GroupBy(tc => tc.Source).Select(g => g.Key); | ||
|
||
// Initialize extension before execution | ||
this.InitializeExtensions(testSources); | ||
|
||
Task.Run(() => executionManager.StartTestRun(testRunCriteria.Tests, testRunCriteria.TestRunSettings, executionContext, null, eventHandler)); | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
EqtTrace.Error("InProcessProxyexecutionManager.StartTestRun: Failed to start test run: {0}", exception); | ||
|
||
// Send exception message. | ||
eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.ToString()); | ||
|
||
// Send a run complete to caller. | ||
var completeArgs = new TestRunCompleteEventArgs(null, false, true, exception, new Collection<AttachmentSet>(), TimeSpan.Zero); | ||
eventHandler.HandleTestRunComplete(completeArgs, null, null, null); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/// <summary> | ||
/// Aborts the test operation. | ||
/// </summary> | ||
public void Abort() | ||
{ | ||
Task.Run(() => this.testHostManagerFactory.GetExecutionManager().Abort()); | ||
} | ||
|
||
/// <summary> | ||
/// Cancels the test run. | ||
/// </summary> | ||
public void Cancel() | ||
{ | ||
Task.Run(() => this.testHostManagerFactory.GetExecutionManager().Cancel()); | ||
} | ||
|
||
/// <summary> | ||
/// Closes the current test operation. | ||
/// This function is of no use in this context as we are not creating any testhost | ||
/// </summary> | ||
public void Close() | ||
{ | ||
} | ||
|
||
|
||
private void InitializeExtensions(IEnumerable<string> sources) | ||
{ | ||
var extensionsFromSource = this.testHostManager.GetTestPlatformExtensions(sources, Enumerable.Empty<string>()); | ||
if (extensionsFromSource.Any()) | ||
{ | ||
TestPluginCache.Instance.UpdateExtensions(extensionsFromSource, false); | ||
} | ||
|
||
// We don't need to pass list of extension as we are running inside vstest.console and | ||
// it will use TestPluginCache of vstest.console | ||
executionManager.Initialize(Enumerable.Empty<string>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we require any null check for this.testHostManagerFactory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't require. If its null, process should catch exception