-
Notifications
You must be signed in to change notification settings - Fork 341
Testhost sharing between discovery & execution #2687
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
Changes from 31 commits
cad90d0
859965e
30775f1
b9057db
bd267b7
03c5c96
80059ae
809d6f4
b831d87
8ebaabc
ff8507b
629f20f
f91228e
3c2e26b
ef039a2
38df898
55118ac
3e43177
b3953b0
58fd909
0c533f5
90170c5
6328248
73fe5d0
7a89d9a
9cfd6bf
4b246a8
a64fd37
b80b578
02d6205
6e75cfc
393fb3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client | |
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
|
|
||
| using Microsoft.VisualStudio.TestPlatform.Common; | ||
| using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; | ||
|
|
@@ -25,17 +26,44 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client | |
| /// </summary> | ||
| public class ProxyDiscoveryManager : IProxyDiscoveryManager, IBaseProxy, ITestDiscoveryEventsHandler2 | ||
| { | ||
| private ProxyOperationManager proxyOperationManager; | ||
| private readonly ITestRuntimeProvider testHostManager; | ||
| private IDataSerializer dataSerializer; | ||
| private bool isCommunicationEstablished; | ||
| private readonly TestSessionInfo testSessionInfo = null; | ||
cvpoienaru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Func<string, ProxyDiscoveryManager, ProxyOperationManager> proxyOperationManagerCreator; | ||
|
|
||
| private ITestRuntimeProvider testHostManager; | ||
| private IRequestData requestData; | ||
|
|
||
| private readonly IFileHelper fileHelper; | ||
| private readonly IDataSerializer dataSerializer; | ||
| private bool isCommunicationEstablished; | ||
|
|
||
| private ManualResetEvent proxyOperationManagerInitializedEvent = new ManualResetEvent(false); | ||
| private ProxyOperationManager proxyOperationManager = null; | ||
| private ITestDiscoveryEventsHandler2 baseTestDiscoveryEventsHandler; | ||
| private bool skipDefaultAdapters; | ||
| private readonly IFileHelper fileHelper; | ||
|
|
||
| #region Constructors | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="testSessionInfo">The test session info.</param> | ||
| /// <param name="proxyOperationManagerCreator">The proxy operation manager creator.</param> | ||
| public ProxyDiscoveryManager( | ||
| TestSessionInfo testSessionInfo, | ||
| Func<string, ProxyDiscoveryManager, ProxyOperationManager> proxyOperationManagerCreator) | ||
| { | ||
| // Filling in test session info and proxy information. | ||
| this.testSessionInfo = testSessionInfo; | ||
| this.proxyOperationManagerCreator = proxyOperationManagerCreator; | ||
|
|
||
| this.requestData = null; | ||
| this.testHostManager = null; | ||
| this.dataSerializer = JsonDataSerializer.Instance; | ||
| this.fileHelper = new FileHelper(); | ||
| this.isCommunicationEstablished = false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class. | ||
| /// </summary> | ||
|
|
@@ -55,9 +83,7 @@ public ProxyDiscoveryManager( | |
| testHostManager, | ||
| JsonDataSerializer.Instance, | ||
| new FileHelper()) | ||
| { | ||
| this.testHostManager = testHostManager; | ||
| } | ||
| { } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class. | ||
|
|
@@ -81,14 +107,16 @@ internal ProxyDiscoveryManager( | |
| IDataSerializer dataSerializer, | ||
| IFileHelper fileHelper) | ||
| { | ||
| this.dataSerializer = dataSerializer; | ||
| this.testHostManager = testHostManager; | ||
| this.isCommunicationEstablished = false; | ||
| this.requestData = requestData; | ||
| this.testHostManager = testHostManager; | ||
|
|
||
| this.dataSerializer = dataSerializer; | ||
| this.fileHelper = fileHelper; | ||
| this.isCommunicationEstablished = false; | ||
|
|
||
| // Create a new proxy operation manager. | ||
| this.proxyOperationManager = new ProxyOperationManager(requestData, requestSender, testHostManager, this); | ||
| this.proxyOperationManagerInitializedEvent.Set(); | ||
| } | ||
|
|
||
| #endregion | ||
|
|
@@ -104,6 +132,17 @@ public void Initialize(bool skipDefaultAdapters) | |
| /// <inheritdoc/> | ||
| public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) | ||
| { | ||
| if (this.proxyOperationManager == null) | ||
| { | ||
| this.proxyOperationManager = this.proxyOperationManagerCreator( | ||
| discoveryCriteria.Sources.First(), | ||
| this); | ||
|
|
||
| this.proxyOperationManagerInitializedEvent.Set(); | ||
| this.testHostManager = this.proxyOperationManager.TestHostManager; | ||
| this.requestData = this.proxyOperationManager.RequestData; | ||
| } | ||
|
|
||
| this.baseTestDiscoveryEventsHandler = eventHandler; | ||
| try | ||
| { | ||
|
|
@@ -149,6 +188,9 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve | |
| /// <inheritdoc/> | ||
| public void Abort() | ||
| { | ||
| // Make sure the proxy operation manager is initialized before anything. | ||
| this.proxyOperationManagerInitializedEvent.WaitOne(); | ||
|
||
|
|
||
| // Cancel fast, try to stop testhost deployment/launch | ||
| this.proxyOperationManager.CancellationTokenSource.Cancel(); | ||
| this.Close(); | ||
|
|
@@ -157,7 +199,22 @@ public void Abort() | |
| /// <inheritdoc/> | ||
| public void Close() | ||
| { | ||
| this.proxyOperationManager.Close(); | ||
| // Make sure the proxy operation manager is initialized before anything. | ||
| this.proxyOperationManagerInitializedEvent.WaitOne(); | ||
|
|
||
| // When no test session is being used we don't share the testhost | ||
| // between test discovery and test run. The testhost is closed upon | ||
| // successfully completing the operation it was spawned for. | ||
| // | ||
| // In contrast, the new workflow (using test sessions) means we should keep | ||
| // the testhost alive until explicitly closed by the test session owner. | ||
| if (this.testSessionInfo == null) | ||
| { | ||
| this.proxyOperationManager.Close(); | ||
| return; | ||
| } | ||
|
|
||
| TestSessionPool.Instance.ReturnProxy(this.testSessionInfo, this.proxyOperationManager.Id); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.