From 1f41e27cdd5c5d9431c3add432357904116bf3b9 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Sat, 14 Apr 2018 11:59:04 +0530 Subject: [PATCH 01/16] Initial commit --- .../Program.cs | 2 +- .../DesignMode/DesignModeClient.cs | 7 ++++- .../DesignMode/DesignModeTestHostLauncher.cs | 5 ++-- .../DesignMode/IDesignModeClient.cs | 5 +++- .../Execution/TestRunRequest.cs | 5 ++++ .../Client/Interfaces/ITestHostLauncher.cs | 5 +++- .../Hosting/DefaultTestHostManager.cs | 2 +- .../CustomTestHostLauncher.cs | 4 +-- .../DesignModeTestHostLauncherTests.cs | 4 +-- .../Execution/TestRunRequestTests.cs | 6 ++-- .../Hosting/DefaultTestHostManagerTests.cs | 6 ++-- .../Hosting/DotnetTestHostManagerTests.cs | 10 +++---- .../VsTestConsoleRequestSenderTests.cs | 28 +++++++++---------- 13 files changed, 53 insertions(+), 36 deletions(-) diff --git a/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs b/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs index 7ac4f60bb5..b1916293a8 100644 --- a/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs +++ b/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs @@ -168,7 +168,7 @@ public CustomTestHostLauncher(Action callback) public bool IsDebug => false; - public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)) { var processInfo = new ProcessStartInfo( defaultTestHostStartInfo.FileName, diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 6d8f1bb033..877faf5cd6 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -238,7 +238,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) /// /// The . /// - public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo) + public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, CancellationToken cancellationToken = default(CancellationToken)) { lock (ackLockObject) { @@ -250,6 +250,11 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo) waitHandle.Set(); }; + // TODO: unresgiter it also. + + // Resgitering cancellationToken to set waitHandle whenever token is cancelled. + cancellationToken.Register(() => waitHandle.Set()); + this.communicationManager.SendMessage(MessageType.CustomTestHostLaunch, testProcessStartInfo); // LifeCycle of the TP through DesignModeClient is maintained by the IDEs or user-facing-clients like LUTs, who call TestPlatform diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs index 92f5fe8291..78f1912388 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode { using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using System.Threading; /// /// DesignMode TestHost Launcher for hosting of test process @@ -26,9 +27,9 @@ public DesignModeTestHostLauncher(IDesignModeClient designModeClient) public virtual bool IsDebug => false; /// - public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)) { - return this.designModeClient.LaunchCustomHost(defaultTestHostStartInfo); + return this.designModeClient.LaunchCustomHost(defaultTestHostStartInfo, cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs index 05399ac9eb..454ad8f852 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using System; + using System.Threading; /// /// The interface for design mode client. @@ -28,7 +29,9 @@ public interface IDesignModeClient : IDisposable /// Send a custom host launch message to IDE /// /// Default TestHost Start Info - int LaunchCustomHost(TestProcessStartInfo defaultTestHostStartInfo); + /// The cancellation Token. + /// Process id of the launched test host. + int LaunchCustomHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)); /// /// Handles parent process exit diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index 610535289c..eaa1ba26cf 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -41,6 +41,11 @@ public class TestRunRequest : ITestRunRequest, ITestRunEventsHandler /// private object syncObject = new Object(); + /// + /// Sync object for cancel operation + /// + private object cancelSyncObject = new Object(); + /// /// The run completion event which will be signalled on completion of test run. /// diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs index bb663ce8e6..5899961aab 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Threading; + namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces { /// @@ -17,7 +19,8 @@ public interface ITestHostLauncher /// Launches custom test host using the default test process start info /// /// Default TestHost Process Info + /// The cancellation Token. /// Process id of the launched test host - int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo); + int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)); // TODO: check if we can remove default value from interface. } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index db0d036239..868edd4ec8 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -383,7 +383,7 @@ private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToke } else { - int processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo); + int processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); this.testHostProcess = Process.GetProcessById(processId); this.processHelper.SetExitCallback(processId, this.ExitCallBack); } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs index 64da144d58..5f56037a79 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs @@ -4,7 +4,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests { using System.Diagnostics; - + using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; @@ -23,7 +23,7 @@ public int ProcessId public bool IsDebug => true; /// md.LaunchCustomHost(testProcessStartInfo), Times.Once); + mockDesignModeClient.Verify(md => md.LaunchCustomHost(testProcessStartInfo, It.IsAny()), Times.Once); } [TestMethod] @@ -40,7 +40,7 @@ public void DesignModeDebugTestHostLauncherLaunchTestHostShouldCallDesignModeCli launcher.LaunchTestHost(testProcessStartInfo); - mockDesignModeClient.Verify(md => md.LaunchCustomHost(testProcessStartInfo), Times.Once); + mockDesignModeClient.Verify(md => md.LaunchCustomHost(testProcessStartInfo, It.IsAny()), Times.Once); } } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs index 746cb9b99c..0b21cdbdb1 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs @@ -617,7 +617,7 @@ public void LaunchProcessWithDebuggerAttachedShouldNotCallCustomLauncherIfTestRu var testProcessStartInfo = new TestProcessStartInfo(); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Never); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Never); } [TestMethod] @@ -633,7 +633,7 @@ public void LaunchProcessWithDebuggerAttachedShouldNotCallCustomLauncherIfLaunch var testProcessStartInfo = new TestProcessStartInfo(); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Never); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Never); } [TestMethod] @@ -650,7 +650,7 @@ public void LaunchProcessWithDebuggerAttachedShouldCallCustomLauncherIfLauncherI mockCustomLauncher.Setup(ml => ml.IsDebug).Returns(true); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(testProcessStartInfo), Times.Once); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(testProcessStartInfo, It.IsAny()), Times.Once); } /// diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index bffb9f85bc..578e0f706d 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -368,13 +368,13 @@ public void LaunchTestHostShouldUseCustomHostIfSet() var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); this.testHostManager.HostLaunched += this.TestHostManagerHostLaunched; Task pid = this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None); pid.Wait(); - mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny()), Times.Once); + mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once); Assert.IsTrue(pid.Result); Assert.AreEqual(currentProcess.Id, this.testHostId); @@ -386,7 +386,7 @@ public void LaunchTestHostShouldSetExitCallbackInCaseCustomHost() var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None).Wait(); this.mockProcessHelper.Verify(ph => ph.SetExitCallback(currentProcess.Id, It.IsAny>())); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 409e683868..6620cd0e81 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -211,7 +211,7 @@ public void GetTestHostProcessStartInfoShouldIncludeEnvironmentVariables() public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); @@ -229,7 +229,7 @@ public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs( public void LaunchTestHostAsyncShouldNotStartHostProcessIfCancellationTokenIsSet() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); @@ -252,7 +252,7 @@ public void LaunchTestHostShouldLaunchProcessWithEnvironmentVariables() processId.Wait(); Assert.IsTrue(processId.Result); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables))), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables)), It.IsAny()), Times.Once); } [TestMethod] @@ -366,14 +366,14 @@ public async Task LaunchTestHostShouldLaunchProcessWithConnectionInfo() this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); await this.dotnetHostManager.LaunchTestHostAsync(this.defaultTestProcessStartInfo, CancellationToken.None); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs))), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs)), It.IsAny()), Times.Once); } [TestMethod] public void LaunchTestHostShouldSetExitCallBackInCaseCustomHost() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index 3b1051d285..e994c52a25 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -993,7 +993,7 @@ public void StartTestRunWithCustomHostShouldComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1004,7 +1004,7 @@ public void StartTestRunWithCustomHostShouldComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1057,7 +1057,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1068,7 +1068,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1107,7 +1107,7 @@ public void StartTestRunWithCustomHostShouldNotAbortAndSendErrorToVstestConsoleI }; var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Throws(new Exception("BadError")); + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Throws(new Exception("BadError")); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1156,7 +1156,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldNotAbortAndSendErrorToVst }; var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Throws(new Exception("BadError")); + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Throws(new Exception("BadError")); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1650,7 +1650,7 @@ public void StartTestRunWithCustomHostWithSelectedTestsComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1661,7 +1661,7 @@ public void StartTestRunWithCustomHostWithSelectedTestsComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1712,7 +1712,7 @@ public async Task StartTestRunWithCustomHostAsyncWithSelectedTestsShouldComplete }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1723,7 +1723,7 @@ public async Task StartTestRunWithCustomHostAsyncWithSelectedTestsShouldComplete It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1747,7 +1747,7 @@ public void StartTestRunWithCustomHostInParallelShouldCallCustomHostMultipleTime var runComplete = CreateMessage(MessageType.ExecutionComplete, completepayload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message1)); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())) + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())) .Callback((startInfo) => { if (startInfo.FileName.Equals(p1.FileName)) @@ -1762,7 +1762,7 @@ public void StartTestRunWithCustomHostInParallelShouldCallCustomHostMultipleTime this.requestSender.InitializeCommunication(); this.requestSender.StartTestRunWithCustomHost(sources, null, new TestPlatformOptions(), mockHandler.Object, mockLauncher.Object); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Exactly(2)); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Exactly(2)); } [TestMethod] @@ -1786,7 +1786,7 @@ public async Task StartTestRunWithCustomHostAsyncInParallelShouldCallCustomHostM var runComplete = CreateMessage(MessageType.ExecutionComplete, completepayload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message1)); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())) + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())) .Callback((startInfo) => { if (startInfo.FileName.Equals(p1.FileName)) @@ -1802,7 +1802,7 @@ public async Task StartTestRunWithCustomHostAsyncInParallelShouldCallCustomHostM await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); await this.requestSenderAsync.StartTestRunWithCustomHostAsync(sources, null, null, mockHandler.Object, mockLauncher.Object); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Exactly(2)); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Exactly(2)); } [TestMethod] From 1b09512cb275c850176829db87dd8bb2e35f1ae5 Mon Sep 17 00:00:00 2001 From: Abhishek Kumawat Date: Mon, 16 Apr 2018 00:48:13 +0530 Subject: [PATCH 02/16] Cancellation in custom host launcher, test host, while ongoing communication --- .../DesignMode/DesignModeClient.cs | 15 ++++-- .../DesignMode/DesignModeTestHostLauncher.cs | 8 ++- .../DesignMode/IDesignModeClient.cs | 2 +- .../Execution/TestRunRequest.cs | 9 +++- .../Interfaces/ITestRequestSender.cs | 25 +++++++++ .../TestRequestSender.cs | 54 ++++++++++++++----- .../Client/ProxyDiscoveryManager.cs | 4 +- .../Client/ProxyExecutionManager.cs | 43 ++++++++------- .../Client/ProxyOperationManager.cs | 37 ++++++++++--- .../Execution/BaseRunTests.cs | 3 ++ .../Client/Interfaces/ITestHostLauncher.cs | 9 +++- .../TestPlatformHelpers/TestRequestManager.cs | 8 --- 12 files changed, 156 insertions(+), 61 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 877faf5cd6..e27fd1e975 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -235,10 +235,13 @@ private void ProcessRequests(ITestRequestManager testRequestManager) /// /// The test Process Start Info. /// + /// + /// The cancellation token. + /// /// /// The . /// - public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, CancellationToken cancellationToken = default(CancellationToken)) + public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, CancellationToken cancellationToken) { lock (ackLockObject) { @@ -250,10 +253,8 @@ private void ProcessRequests(ITestRequestManager testRequestManager) waitHandle.Set(); }; - // TODO: unresgiter it also. - - // Resgitering cancellationToken to set waitHandle whenever token is cancelled. - cancellationToken.Register(() => waitHandle.Set()); + // Registering cancellationToken to set waitHandle (whenever request is cancelled). + var cancellationTokenRegistration = cancellationToken.Register(() => waitHandle.Set()); this.communicationManager.SendMessage(MessageType.CustomTestHostLaunch, testProcessStartInfo); @@ -263,6 +264,10 @@ private void ProcessRequests(ITestRequestManager testRequestManager) // Even if TP can abort the API somehow, TP is essentially putting IDEs or Clients in inconsistent state without having info on // Since the IDEs own user-UI-experience here, TP will let the custom host launch as much time as IDEs define it for their users waitHandle.WaitOne(); + + cancellationTokenRegistration.Dispose(); + cancellationToken.ThrowIfCancellationRequested(); + this.onAckMessageReceived = null; var ackPayload = this.dataSerializer.DeserializePayload(ackMessage); diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs index 78f1912388..24a74fbf94 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs @@ -27,7 +27,13 @@ public DesignModeTestHostLauncher(IDesignModeClient designModeClient) public virtual bool IsDebug => false; /// - public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)) + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) + { + return this.designModeClient.LaunchCustomHost(defaultTestHostStartInfo, CancellationToken.None); + } + + /// + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken) { return this.designModeClient.LaunchCustomHost(defaultTestHostStartInfo, cancellationToken); } diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs index 454ad8f852..1086ab6b32 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs @@ -31,7 +31,7 @@ public interface IDesignModeClient : IDisposable /// Default TestHost Start Info /// The cancellation Token. /// Process id of the launched test host. - int LaunchCustomHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)); + int LaunchCustomHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken); /// /// Handles parent process exit diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index eaa1ba26cf..9f1e92a732 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -46,6 +46,11 @@ public class TestRunRequest : ITestRunRequest, ITestRunEventsHandler /// private object cancelSyncObject = new Object(); + /// + /// Sync object for abort operation + /// + private object abortSyncObject = new Object(); + /// /// The run completion event which will be signalled on completion of test run. /// @@ -241,7 +246,7 @@ public void CancelAsync() { EqtTrace.Verbose("TestRunRequest.CancelAsync: Canceling."); - lock (this.syncObject) + lock (this.cancelSyncObject) { if (this.disposed) { @@ -270,7 +275,7 @@ public void Abort() { EqtTrace.Verbose("TestRunRequest.Abort: Aborting."); - lock (this.syncObject) + lock (this.abortSyncObject) { if (this.disposed) { diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs index e053941fa1..54ce9b5129 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces { using System; using System.Collections.Generic; + using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -32,6 +33,14 @@ public interface ITestRequestSender : IDisposable /// True, if Handler is connected bool WaitForRequestHandlerConnection(int connectionTimeout); + /// + /// Waits for Request Handler to be connected + /// + /// Time to wait for connection + /// Cancellation token + /// True, if Handler is connected + bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationToken cancellationToken); + /// /// Close the Sender /// @@ -63,6 +72,14 @@ public interface ITestRequestSender : IDisposable /// EventHandler for test run events void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler); + /// + /// Starts the TestRun with given sources and criteria + /// + /// RunCriteria for test run + /// EventHandler for test run events + /// Cancellation token + void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken); + /// /// Starts the TestRun with given test cases and criteria /// @@ -70,6 +87,14 @@ public interface ITestRequestSender : IDisposable /// EventHandler for test run events void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler); + /// + /// Starts the TestRun with given test cases and criteria + /// + /// RunCriteria for test run + /// EventHandler for test run events + /// Cancellation token + void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken); + /// /// Ends the Session /// diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index 874bdd3b2e..7010ae3208 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -137,12 +137,22 @@ public int InitializeCommunication() /// public bool WaitForRequestHandlerConnection(int connectionTimeout) { + return this.WaitForRequestHandlerConnection(connectionTimeout, CancellationToken.None); + } + + /// + public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationToken cancellationToken) + { + var cancellationTokenRegistration = cancellationToken.Register(() => this.connected.Set()); if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose("TestRequestSender.WaitForRequestHandlerConnection: waiting for connection with timeout: {0}", connectionTimeout); } - return this.connected.Wait(connectionTimeout); + var waitSuccess = this.connected.Wait(connectionTimeout) && !cancellationToken.IsCancellationRequested; + cancellationTokenRegistration.Dispose(); + + return waitSuccess; } /// @@ -260,13 +270,19 @@ public void InitializeExecution(IEnumerable pathToAdditionalExtensions) /// public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler) + { + this.StartTestRun(runCriteria, eventHandler, CancellationToken.None); + } + + /// + public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) { this.messageEventHandler = eventHandler; this.onDisconnected = (disconnectedEventArgs) => { - this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true); + this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true, cancellationToken); }; - this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler); + this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler, cancellationToken); this.channel.MessageReceived += this.onMessageReceived; var message = this.dataSerializer.SerializePayload( @@ -284,13 +300,19 @@ public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsH /// public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler) + { + this.StartTestRun(runCriteria, eventHandler, CancellationToken.None); + } + + /// + public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) { this.messageEventHandler = eventHandler; this.onDisconnected = (disconnectedEventArgs) => { - this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true); + this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true, cancellationToken); }; - this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler); + this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler, cancellationToken); this.channel.MessageReceived += this.onMessageReceived; var message = this.dataSerializer.SerializePayload( @@ -379,7 +401,7 @@ public void Dispose() this.communicationEndpoint.Stop(); } - private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs messageReceived, ITestRunEventsHandler testRunEventsHandler) + private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs messageReceived, ITestRunEventsHandler testRunEventsHandler, CancellationToken cancellationToken) { try { @@ -434,7 +456,7 @@ private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs } catch (Exception exception) { - this.OnTestRunAbort(testRunEventsHandler, exception, false); + this.OnTestRunAbort(testRunEventsHandler, exception, false, cancellationToken); } } @@ -485,7 +507,7 @@ private void OnDiscoveryMessageReceived(ITestDiscoveryEventsHandler2 discoveryEv } } - private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exception exception, bool getClientError) + private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exception exception, bool getClientError, CancellationToken cancellationToken) { if (this.IsOperationComplete()) { @@ -496,7 +518,7 @@ private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exceptio EqtTrace.Verbose("TestRequestSender: OnTestRunAbort: Set operation complete."); this.SetOperationComplete(); - var reason = this.GetAbortErrorMessage(exception, getClientError); + var reason = this.GetAbortErrorMessage(exception, getClientError, cancellationToken); EqtTrace.Error("TestRequestSender: Aborting test run because {0}", reason); this.LogErrorMessage(string.Format(CommonResources.AbortedTestRun, reason)); @@ -522,7 +544,7 @@ private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Excepti this.SetOperationComplete(); var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(-1, true); - var reason = this.GetAbortErrorMessage(exception, getClientError); + var reason = this.GetAbortErrorMessage(exception, getClientError, CancellationToken.None); EqtTrace.Error("TestRequestSender: Aborting test discovery because {0}", reason); this.LogErrorMessage(string.Format(CommonResources.AbortedTestDiscovery, reason)); @@ -540,8 +562,9 @@ private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Excepti eventHandler.HandleDiscoveryComplete(discoveryCompleteEventArgs, null); } - private string GetAbortErrorMessage(Exception exception, bool getClientError) + private string GetAbortErrorMessage(Exception exception, bool getClientError, CancellationToken cancellationToken) { + var cancellationTokenRegistration = cancellationToken.Register(() => this.clientExited.Set()); EqtTrace.Verbose("TestRequestSender: GetAbortErrorMessage: Exception: " + exception); // It is also possible for an operation to abort even if client has not @@ -554,15 +577,18 @@ private string GetAbortErrorMessage(Exception exception, bool getClientError) // Set a default message and wait for test host to exit for a moment reason = CommonResources.UnableToCommunicateToTestHost; - if (this.clientExited.Wait(this.clientExitedWaitTime)) + if (this.clientExited.Wait(this.clientExitedWaitTime) && !cancellationToken.IsCancellationRequested) { EqtTrace.Info("TestRequestSender: GetAbortErrorMessage: Received test host error message."); reason = this.clientExitErrorMessage; } - - EqtTrace.Info("TestRequestSender: GetAbortErrorMessage: Timed out waiting for test host error message."); + else + { + EqtTrace.Info("TestRequestSender: GetAbortErrorMessage: Timed out waiting for test host error message."); + } } + cancellationTokenRegistration.Dispose(); return reason; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs index 61b87c7a1b..7f42b11bed 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs @@ -27,7 +27,6 @@ public class ProxyDiscoveryManager : ProxyOperationManager, IProxyDiscoveryManag { private readonly ITestRuntimeProvider testHostManager; private IDataSerializer dataSerializer; - private CancellationTokenSource cancellationTokenSource; private bool isCommunicationEstablished; private IRequestData requestData; private ITestDiscoveryEventsHandler2 baseTestDiscoveryEventsHandler; @@ -71,7 +70,6 @@ internal ProxyDiscoveryManager( { this.dataSerializer = dataSerializer; this.testHostManager = testHostManager; - this.cancellationTokenSource = new CancellationTokenSource(); this.isCommunicationEstablished = false; this.requestData = requestData; } @@ -99,7 +97,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve this.baseTestDiscoveryEventsHandler = eventHandler; try { - this.isCommunicationEstablished = this.SetupChannel(discoveryCriteria.Sources, this.cancellationTokenSource.Token); + this.isCommunicationEstablished = this.SetupChannel(discoveryCriteria.Sources); if (this.isCommunicationEstablished) { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index bf979588e4..cc0df87274 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -31,7 +31,6 @@ internal class ProxyExecutionManager : ProxyOperationManager, IProxyExecutionMan { private readonly ITestRuntimeProvider testHostManager; private IDataSerializer dataSerializer; - private CancellationTokenSource cancellationTokenSource; private bool isCommunicationEstablished; private IRequestData requestData; private ITestRunEventsHandler baseTestRunEventsHandler; @@ -67,7 +66,6 @@ internal ProxyExecutionManager(IRequestData requestData, ITestRequestSender requ { this.testHostManager = testHostManager; this.dataSerializer = dataSerializer; - this.cancellationTokenSource = new CancellationTokenSource(); this.isCommunicationEstablished = false; this.requestData = requestData; } @@ -102,24 +100,14 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH { EqtTrace.Verbose("ProxyExecutionManager: Test host is always Lazy initialize."); } - var testPackages = new List(testRunCriteria.HasSpecificSources ? testRunCriteria.Sources : // If the test execution is with a test filter, group them by sources testRunCriteria.Tests.GroupBy(tc => tc.Source).Select(g => g.Key)); - this.isCommunicationEstablished = this.SetupChannel(testPackages, this.cancellationTokenSource.Token); + this.isCommunicationEstablished = this.SetupChannel(testPackages); if (this.isCommunicationEstablished) { - if (this.cancellationTokenSource.IsCancellationRequested) - { - if (EqtTrace.IsVerboseEnabled) - { - EqtTrace.Verbose("ProxyExecutionManager.StartTestRun: Canceling the current run after getting cancelation request."); - } - throw new TestPlatformException(Resources.Resources.CancelationRequested); - } - this.InitializeExtensions(testPackages); // This code should be in sync with InProcessProxyExecutionManager.StartTestRun executionContext @@ -141,14 +129,12 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH if (testRunCriteria.HasSpecificSources) { var runRequest = testRunCriteria.CreateTestRunCriteriaForSources(testHostManager, runsettings, executionContext, testPackages); - - this.RequestSender.StartTestRun(runRequest, this); + this.StartTestRunWithSources(runRequest, this); } else { var runRequest = testRunCriteria.CreateTestRunCriteriaForTests(testHostManager, runsettings, executionContext, testPackages); - - this.RequestSender.StartTestRun(runRequest, this); + this.StartTestRunWithTests(runRequest, this); } } } @@ -187,7 +173,7 @@ public virtual void Cancel(ITestRunEventsHandler eventHandler) } // Cancel fast, try to stop testhost deployment/launch - this.cancellationTokenSource.Cancel(); + this.CancellationTokenSource.Cancel(); if (this.isCommunicationEstablished) { this.RequestSender.SendTestRunCancel(); @@ -212,7 +198,13 @@ public void Abort(ITestRunEventsHandler eventHandler) this.baseTestRunEventsHandler = eventHandler; } - this.RequestSender.SendTestRunAbort(); + // Cancel fast, try to stop testhost deployment/launch + this.CancellationTokenSource.Cancel(); + + if (this.isCommunicationEstablished) + { + this.RequestSender.SendTestRunAbort(); + } } /// @@ -260,6 +252,7 @@ private void LogMessage(TestMessageLevel testMessageLevel, string message) private void InitializeExtensions(IEnumerable sources) { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); var extensions = TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.TestAdapterEndsWithPattern, this.skipDefaultAdapters); var sourceList = sources.ToList(); var platformExtensions = this.testHostManager.GetTestPlatformExtensions(sourceList, extensions).ToList(); @@ -270,5 +263,17 @@ private void InitializeExtensions(IEnumerable sources) this.RequestSender.InitializeExecution(platformExtensions); } } + + private void StartTestRunWithTests(TestRunCriteriaWithTests runRequest, ProxyExecutionManager proxyExecutionManager) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + this.RequestSender.StartTestRun(runRequest, this, this.CancellationTokenSource.Token); + } + + private void StartTestRunWithSources(TestRunCriteriaWithSources runRequest, ProxyExecutionManager proxyExecutionManager) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + this.RequestSender.StartTestRun(runRequest, this, this.CancellationTokenSource.Token); + } } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index aa6c886d12..c66b531922 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -55,6 +55,8 @@ public abstract class ProxyOperationManager protected ProxyOperationManager(IRequestData requestData, ITestRequestSender requestSender, ITestRuntimeProvider testHostManager, int clientConnectionTimeout) { this.RequestSender = requestSender; + this.CancellationTokenSource = new CancellationTokenSource(); + this.connectionTimeout = clientConnectionTimeout; this.testHostManager = testHostManager; this.processHelper = new ProcessHelper(); @@ -75,6 +77,11 @@ protected ProxyOperationManager(IRequestData requestData, ITestRequestSender req /// protected ITestRequestSender RequestSender { get; set; } + /// + /// Gets or sets the cancellation token source. + /// + protected CancellationTokenSource CancellationTokenSource { get; set; } + #endregion #region IProxyOperationManager implementation. @@ -91,8 +98,9 @@ protected ProxyOperationManager(IRequestData requestData, ITestRequestSender req /// /// Returns true if Communation is established b/w runner and host /// - public virtual bool SetupChannel(IEnumerable sources, CancellationToken cancellationToken) + public virtual bool SetupChannel(IEnumerable sources) { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); var connTimeout = this.connectionTimeout; var userSpecifiedTimeout = Environment.GetEnvironmentVariable("VSTEST_CONNECTION_TIMEOUT"); @@ -114,7 +122,6 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken } var processId = this.processHelper.GetCurrentProcessId(); - var connectionInfo = new TestRunnerConnectionInfo { Port = portNumber, ConnectionInfo = testHostConnectionInfo, RunnerProcessId = processId, LogFile = this.GetTimestampedLogFile(EqtTrace.LogFile) }; // Subscribe to TestHost Event @@ -126,8 +133,7 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken try { // Launch the test host. - var hostLaunchedTask = this.testHostManager.LaunchTestHostAsync(testHostStartInfo, cancellationToken); - this.testHostLaunched = hostLaunchedTask.Result; + var testHostLaunched = this.LaunchTestHostAsync(testHostStartInfo, this.CancellationTokenSource.Token); if (this.testHostLaunched && testHostConnectionInfo.Role == ConnectionRole.Host) { @@ -155,10 +161,9 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken } // Wait for a timeout for the client to connect. - if (!this.testHostLaunched || !this.RequestSender.WaitForRequestHandlerConnection(connTimeout)) + if (!this.testHostLaunched || !this.WaitForRequestHandlerConnection(connTimeout)) { var errorMsg = CrossPlatEngineResources.InitializationFailed; - if (!string.IsNullOrWhiteSpace(this.testHostProcessStdError)) { // Testhost failed with error @@ -175,7 +180,7 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken if (this.versionCheckRequired) { - this.RequestSender.CheckVersionWithTestHost(); + this.CheckVersionWithTestHost(); } this.initialized = true; @@ -184,6 +189,24 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken return true; } + private bool LaunchTestHostAsync(TestProcessStartInfo testHostStartInfo, CancellationToken token) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + return this.testHostManager.LaunchTestHostAsync(testHostStartInfo, token).Result; + } + + private bool WaitForRequestHandlerConnection(int connTimeout) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + return this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token); + } + + private void CheckVersionWithTestHost() + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + this.RequestSender.CheckVersionWithTestHost(); + } + /// /// Closes the channel, terminate test host process. /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs index fec3391f2d..8361a80d67 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs @@ -287,6 +287,9 @@ internal void Abort() /// internal void Cancel() { + // Note: Test host delegates the cancellation to active executor and doesn't call HandleTestRunComplete in cancel request. + // Its expected from active executor to respect the cancel request and thus return from RunTests quickly (cancelling the tests). + isCancellationRequested = true; if (this.activeExecutor == null) diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs index 5899961aab..b49eaa7a86 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/ITestHostLauncher.cs @@ -15,12 +15,19 @@ public interface ITestHostLauncher /// bool IsDebug { get; } + /// + /// Launches custom test host using the default test process start info + /// + /// Default TestHost Process Info + /// Process id of the launched test host + int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo); + /// /// Launches custom test host using the default test process start info /// /// Default TestHost Process Info /// The cancellation Token. /// Process id of the launched test host - int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)); // TODO: check if we can remove default value from interface. + int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken); } } diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 7aa8465f48..956a3fc64e 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -59,8 +59,6 @@ internal class TestRequestManager : ITestRequestManager /// private ITestRunRequest currentTestRunRequest; - private readonly EventWaitHandle runRequestStartedEventHandle = new AutoResetEvent(false); - private object syncobject = new object(); private Task metricsPublisher; @@ -295,8 +293,6 @@ public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc public void CancelTestRun() { EqtTrace.Info("TestRequestManager.CancelTestRun: Sending cancel request."); - - this.runRequestStartedEventHandle.WaitOne(runRequestTimeout); this.currentTestRunRequest?.CancelAsync(); } @@ -306,8 +302,6 @@ public void CancelTestRun() public void AbortTestRun() { EqtTrace.Info("TestRequestManager.AbortTestRun: Sending abort request."); - - this.runRequestStartedEventHandle.WaitOne(runRequestTimeout); this.currentTestRunRequest?.Abort(); } @@ -517,8 +511,6 @@ private void RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, this.testPlatformEventSource.ExecutionRequestStart(); this.currentTestRunRequest.ExecuteAsync(); - - this.runRequestStartedEventHandle.Set(); // Wait for the run completion event this.currentTestRunRequest.WaitForCompletion(); From 60b74d874a57fa42a07675af758eb717e464bb83 Mon Sep 17 00:00:00 2001 From: Abhishek Kumawat Date: Mon, 16 Apr 2018 00:56:54 +0530 Subject: [PATCH 03/16] passing cancellation to data collectors. --- .../DataCollectionRequestSender.cs | 2 +- .../ProxyExecutionManagerWithDataCollection.cs | 15 +-------------- .../DataCollectionTestRunEventsHandler.cs | 11 +++++++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs index 40e19c69f6..22b16e4944 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs @@ -160,7 +160,7 @@ public Collection SendAfterTestRunStartAndGetResult(ITestMessageE // Cycle through the messages that the datacollector sends. // Currently each of the operations are not separate tasks since they should not each take much time. This is just a notification. - while (!isDataCollectionComplete) + while (!isDataCollectionComplete && !isCancelled) { var message = this.communicationManager.ReceiveMessage(); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs index 31fd0acc0e..7547ecda51 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManagerWithDataCollection.cs @@ -112,7 +112,7 @@ public override int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEvents var currentEventHandler = eventHandler; if (this.ProxyDataCollectionManager != null) { - currentEventHandler = new DataCollectionTestRunEventsHandler(eventHandler, this.ProxyDataCollectionManager); + currentEventHandler = new DataCollectionTestRunEventsHandler(eventHandler, this.ProxyDataCollectionManager, this.CancellationTokenSource.Token); } // Log all the messages that are reported while initializing DataCollectionClient @@ -129,19 +129,6 @@ public override int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEvents return base.StartTestRun(testRunCriteria, currentEventHandler); } - /// - public override void Cancel(ITestRunEventsHandler eventHandler) - { - try - { - this.ProxyDataCollectionManager.AfterTestRunEnd(isCanceled: true, runEventsHandler: this.DataCollectionRunEventsHandler); - } - finally - { - base.Cancel(eventHandler); - } - } - public override int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessStartInfo) { if (this.dataCollectionEnvironmentVariables != null) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionTestRunEventsHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionTestRunEventsHandler.cs index 9b36171906..c14dd3c9ad 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionTestRunEventsHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionTestRunEventsHandler.cs @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; + using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -24,6 +25,7 @@ internal class DataCollectionTestRunEventsHandler : ITestRunEventsHandler { private IProxyDataCollectionManager proxyDataCollectionManager; private ITestRunEventsHandler testRunEventsHandler; + private CancellationToken cancellationToken; private IDataSerializer dataSerializer; private Collection dataCollectionAttachmentSets; @@ -36,8 +38,8 @@ internal class DataCollectionTestRunEventsHandler : ITestRunEventsHandler /// /// The proxy Data Collection Manager. /// - public DataCollectionTestRunEventsHandler(ITestRunEventsHandler baseTestRunEventsHandler, IProxyDataCollectionManager proxyDataCollectionManager) - : this(baseTestRunEventsHandler, proxyDataCollectionManager, JsonDataSerializer.Instance) + public DataCollectionTestRunEventsHandler(ITestRunEventsHandler baseTestRunEventsHandler, IProxyDataCollectionManager proxyDataCollectionManager, CancellationToken cancellationToken) + : this(baseTestRunEventsHandler, proxyDataCollectionManager, cancellationToken, JsonDataSerializer.Instance) { } @@ -53,10 +55,11 @@ public DataCollectionTestRunEventsHandler(ITestRunEventsHandler baseTestRunEvent /// /// The data Serializer. /// - public DataCollectionTestRunEventsHandler(ITestRunEventsHandler baseTestRunEventsHandler, IProxyDataCollectionManager proxyDataCollectionManager, IDataSerializer dataSerializer) + public DataCollectionTestRunEventsHandler(ITestRunEventsHandler baseTestRunEventsHandler, IProxyDataCollectionManager proxyDataCollectionManager, CancellationToken cancellationToken, IDataSerializer dataSerializer) { this.proxyDataCollectionManager = proxyDataCollectionManager; this.testRunEventsHandler = baseTestRunEventsHandler; + this.cancellationToken = cancellationToken; this.dataSerializer = dataSerializer; } @@ -87,7 +90,7 @@ public void HandleRawMessage(string rawMessage) if (string.Equals(MessageType.ExecutionComplete, message.MessageType)) { - this.dataCollectionAttachmentSets = this.proxyDataCollectionManager?.AfterTestRunEnd(false, this); + this.dataCollectionAttachmentSets = this.proxyDataCollectionManager?.AfterTestRunEnd(this.cancellationToken.IsCancellationRequested, this); if (this.dataCollectionAttachmentSets != null && this.dataCollectionAttachmentSets.Any()) { From 51bcc10f60f256cbf48ba8d0d7f7db1444f0f999 Mon Sep 17 00:00:00 2001 From: Abhishek Kumawat Date: Mon, 16 Apr 2018 07:05:15 +0530 Subject: [PATCH 04/16] build issues fix --- .../Program.cs | 7 ++- .../Client/ProxyOperationManager.cs | 2 +- .../CustomTestHostLauncher.cs | 12 +++-- .../DesignMode/DesignModeClientTests.cs | 4 +- .../Execution/TestRunRequestTests.cs | 6 +-- .../Client/ProxyExecutionManagerTests.cs | 6 +-- .../Client/ProxyOperationManagerTests.cs | 50 +++++++++---------- ...DataCollectionTestRunEventsHandlerTests.cs | 4 +- .../Hosting/DefaultTestHostManagerTests.cs | 7 +-- .../Hosting/DotnetTestHostManagerTests.cs | 10 ++-- .../VsTestConsoleRequestSenderTests.cs | 28 +++++------ 11 files changed, 74 insertions(+), 62 deletions(-) diff --git a/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs b/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs index b1916293a8..faa74b3763 100644 --- a/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs +++ b/samples/Microsoft.TestPlatform.TranslationLayer.E2ETest/Program.cs @@ -168,7 +168,7 @@ public CustomTestHostLauncher(Action callback) public bool IsDebug => false; - public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken = default(CancellationToken)) + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken) { var processInfo = new ProcessStartInfo( defaultTestHostStartInfo.FileName, @@ -192,6 +192,11 @@ public CustomTestHostLauncher(Action callback) throw new Exception("Process in invalid state."); } + + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) + { + return this.LaunchTestHost(defaultTestHostStartInfo, CancellationToken.None); + } } public class DiscoveryEventHandler : ITestDiscoveryEventsHandler diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index c66b531922..c00e5c823d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -133,7 +133,7 @@ public virtual bool SetupChannel(IEnumerable sources) try { // Launch the test host. - var testHostLaunched = this.LaunchTestHostAsync(testHostStartInfo, this.CancellationTokenSource.Token); + this.testHostLaunched = this.LaunchTestHostAsync(testHostStartInfo, this.CancellationTokenSource.Token); if (this.testHostLaunched && testHostConnectionInfo.Role == ConnectionRole.Host) { diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs index 5f56037a79..f96f9d7efa 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostLauncher.cs @@ -19,11 +19,17 @@ public int ProcessId private set; } - /// public bool IsDebug => true; - /// + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo) + { + return this.LaunchTestHost(defaultTestHostStartInfo, CancellationToken.None); + } + + /// + public int LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo, CancellationToken cancellationToken) { var processInfo = new ProcessStartInfo( defaultTestHostStartInfo.FileName, diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index c2cb902ce5..2f721d6acd 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -285,7 +285,7 @@ public void DesignModeClientLaunchCustomHostMustReturnIfAckComes() Callback(() => Task.Run(sendMessageAction)); var info = new TestProcessStartInfo(); - var processId = testableDesignModeClient.LaunchCustomHost(info); + var processId = testableDesignModeClient.LaunchCustomHost(info, CancellationToken.None); Assert.AreEqual(expectedProcessId, processId); } @@ -309,7 +309,7 @@ public void DesignModeClientLaunchCustomHostMustThrowIfInvalidAckComes() .Callback(() => Task.Run(sendMessageAction)); var info = new TestProcessStartInfo(); - testableDesignModeClient.LaunchCustomHost(info); + testableDesignModeClient.LaunchCustomHost(info, CancellationToken.None); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs index 0b21cdbdb1..746cb9b99c 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/Execution/TestRunRequestTests.cs @@ -617,7 +617,7 @@ public void LaunchProcessWithDebuggerAttachedShouldNotCallCustomLauncherIfTestRu var testProcessStartInfo = new TestProcessStartInfo(); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Never); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Never); } [TestMethod] @@ -633,7 +633,7 @@ public void LaunchProcessWithDebuggerAttachedShouldNotCallCustomLauncherIfLaunch var testProcessStartInfo = new TestProcessStartInfo(); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Never); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Never); } [TestMethod] @@ -650,7 +650,7 @@ public void LaunchProcessWithDebuggerAttachedShouldCallCustomLauncherIfLauncherI mockCustomLauncher.Setup(ml => ml.IsDebug).Returns(true); testRunRequest.LaunchProcessWithDebuggerAttached(testProcessStartInfo); - mockCustomLauncher.Verify(ml => ml.LaunchTestHost(testProcessStartInfo, It.IsAny()), Times.Once); + mockCustomLauncher.Verify(ml => ml.LaunchTestHost(testProcessStartInfo), Times.Once); } /// diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index 29a3c50a44..37be35c64a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -276,7 +276,7 @@ public void SetupChannelShouldThrowExceptionIfClientConnectionTimeout() this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); - Assert.ThrowsException(() => this.testExecutionManager.SetupChannel(new List { "source.dll" }, CancellationToken.None)); + Assert.ThrowsException(() => this.testExecutionManager.SetupChannel(new List { "source.dll" })); } [TestMethod] @@ -430,7 +430,7 @@ public void CloseShouldSignalToServerSessionEndIfTestHostWasLaunched() { this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); - this.testExecutionManager.SetupChannel(new List { "source.dll" }, CancellationToken.None); + this.testExecutionManager.SetupChannel(new List { "source.dll" }); this.testExecutionManager.Close(); @@ -450,7 +450,7 @@ public void CloseShouldSignalServerSessionEndEachTime() { this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); - this.testExecutionManager.SetupChannel(new List { "source.dll" }, CancellationToken.None); + this.testExecutionManager.SetupChannel(new List { "source.dll" }); this.testExecutionManager.Close(); this.testExecutionManager.Close(); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 6e047c7b83..b751ef79f0 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -66,7 +66,7 @@ public void SetupChannelShouldLaunchTestHost() th => th.GetTestHostProcessStartInfo(Enumerable.Empty(), null, It.IsAny())) .Returns(expectedStartInfo); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockTestHostManager.Verify(thl => thl.LaunchTestHostAsync(It.Is(si => si == expectedStartInfo), It.IsAny()), Times.Once); } @@ -77,7 +77,7 @@ public void SetupChannelShouldCreateTimestampedLogFileForHost() this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123); EqtTrace.InitializeVerboseTrace("log.txt"); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockTestHostManager.Verify( th => @@ -99,7 +99,7 @@ public void SetupChannelShouldAddRunnerProcessIdForTestHost() { this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockTestHostManager.Verify( th => @@ -112,7 +112,7 @@ public void SetupChannelShouldAddRunnerProcessIdForTestHost() [TestMethod] public void SetupChannelShouldSetupServerForCommunication() { - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(s => s.InitializeCommunication(), Times.Once); } @@ -139,7 +139,7 @@ public void SetupChannelShouldCallHostServerIfRunnerIsServer() var localTestOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, testRequestSender, this.mockTestHostManager.Object, this.connectionTimeout); - localTestOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + localTestOperationManager.SetupChannel(Enumerable.Empty()); mockCommunicationServer.Verify(s => s.Start(IPAddress.Loopback.ToString()+":0"), Times.Once); } @@ -170,7 +170,7 @@ public void SetupChannelShouldCallSetupClientIfRunnerIsClient() var localTestOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, testRequestSender, this.mockTestHostManager.Object, this.connectionTimeout); - localTestOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + localTestOperationManager.SetupChannel(Enumerable.Empty()); mockCommunicationEndpoint.Verify(s => s.Start(It.IsAny()), Times.Once); } @@ -178,8 +178,8 @@ public void SetupChannelShouldCallSetupClientIfRunnerIsClient() [TestMethod] public void SetupChannelShouldNotInitializeIfConnectionIsAlreadyInitialized() { - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(s => s.InitializeCommunication(), Times.Once); } @@ -187,7 +187,7 @@ public void SetupChannelShouldNotInitializeIfConnectionIsAlreadyInitialized() [TestMethod] public void SetupChannelShouldWaitForTestHostConnection() { - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Once); } @@ -195,8 +195,8 @@ public void SetupChannelShouldWaitForTestHostConnection() [TestMethod] public void SetupChannelShouldNotWaitForTestHostConnectionIfConnectionIsInitialized() { - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Exactly(1)); } @@ -207,7 +207,7 @@ public void SetupChannelShouldHonorTimeOutSetByUser() Environment.SetEnvironmentVariable("VSTEST_CONNECTION_TIMEOUT", "100"); this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(100000)).Returns(true); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(100000), Times.Exactly(1)); @@ -219,7 +219,7 @@ public void SetupChannelShouldNotHonorGarbageTimeOutSetByUser() { Environment.SetEnvironmentVariable("VSTEST_CONNECTION_TIMEOUT", "garbage"); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Exactly(1)); } @@ -232,7 +232,7 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout); - Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None)); + Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); } [TestMethod] @@ -243,13 +243,13 @@ public void SetupChannelShouldThrowIfLaunchTestHostFails() var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout); - Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None)); + Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); } [TestMethod] public void SetupChannelShouldCheckVersionWithTestHost() { - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Once); } @@ -258,7 +258,7 @@ public void SetupChannelShouldThrowExceptionIfVersionCheckFails() { // Make the version check fail this.mockRequestSender.Setup(rs => rs.CheckVersionWithTestHost()).Throws(new TestPlatformException("Version check failed")); - Assert.ThrowsException(() => this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None)); + Assert.ThrowsException(() => this.testOperationManager.SetupChannel(Enumerable.Empty())); } [TestMethod] @@ -268,7 +268,7 @@ public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredFalseShoul var testHostManager = new TestableDotnetTestHostManager(false, this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockEnvironment.Object); var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, testHostManager, this.connectionTimeout); - operationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + operationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Never); } @@ -280,7 +280,7 @@ public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredTrueShould var testHostManager = new TestableDotnetTestHostManager(true, this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockEnvironment.Object); var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, testHostManager, this.connectionTimeout); - operationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + operationManager.SetupChannel(Enumerable.Empty()); this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Once); } @@ -289,7 +289,7 @@ public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredTrueShould public void CloseShouldEndSessionIfHostWasLaunched() { this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); @@ -317,11 +317,11 @@ public void CloseShouldResetChannelInitialization() { this.SetupWaitForTestHostExit(); this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.mockTestHostManager.Verify(th => th.LaunchTestHostAsync(It.IsAny(), It.IsAny()), Times.Exactly(2)); } @@ -330,7 +330,7 @@ public void CloseShouldTerminateTesthostProcessIfWaitTimesout() { // Ensure testhost start returns a dummy process id this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); - this.testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); @@ -380,7 +380,7 @@ public void UpdateTestProcessStartInfoShouldUpdateTelemetryOptedInArgTrueIfTelem .Returns(Task.FromResult(true)); // Act. - testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + testOperationManager.SetupChannel(Enumerable.Empty()); // Verify. Assert.IsTrue(receivedTestProcessInfo.Arguments.Contains("--telemetryoptedin true")); @@ -406,7 +406,7 @@ public void UpdateTestProcessStartInfoShouldUpdateTelemetryOptedInArgFalseIfTele .Returns(Task.FromResult(true)); // Act. - testOperationManager.SetupChannel(Enumerable.Empty(), CancellationToken.None); + testOperationManager.SetupChannel(Enumerable.Empty()); // Verify. Assert.IsTrue(receivedTestProcessInfo.Arguments.Contains("--telemetryoptedin false")); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs index c64c23d2b2..7411276528 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs @@ -6,7 +6,7 @@ namespace TestPlatform.CommunicationUtilities.UnitTests.ObjectModel using System; using System.Collections.ObjectModel; using System.Linq; - + using System.Threading; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; @@ -33,7 +33,7 @@ public void InitializeTests() this.baseTestRunEventsHandler = new Mock(); this.proxyDataCollectionManager = new Mock(); this.mockDataSerializer = new Mock(); - this.testRunEventHandler = new DataCollectionTestRunEventsHandler(this.baseTestRunEventsHandler.Object, this.proxyDataCollectionManager.Object, this.mockDataSerializer.Object); + this.testRunEventHandler = new DataCollectionTestRunEventsHandler(this.baseTestRunEventsHandler.Object, this.proxyDataCollectionManager.Object, CancellationToken.None, this.mockDataSerializer.Object); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 578e0f706d..9ce2d94750 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -365,16 +365,17 @@ public void DefaultTestHostManagerShouldBeShared() [TestMethod] public void LaunchTestHostShouldUseCustomHostIfSet() { + System.Diagnostics.Debugger.Launch(); var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); this.testHostManager.HostLaunched += this.TestHostManagerHostLaunched; Task pid = this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None); pid.Wait(); - mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once); + mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny()), Times.Once); Assert.IsTrue(pid.Result); Assert.AreEqual(currentProcess.Id, this.testHostId); @@ -386,7 +387,7 @@ public void LaunchTestHostShouldSetExitCallbackInCaseCustomHost() var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None).Wait(); this.mockProcessHelper.Verify(ph => ph.SetExitCallback(currentProcess.Id, It.IsAny>())); diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 6620cd0e81..409e683868 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -211,7 +211,7 @@ public void GetTestHostProcessStartInfoShouldIncludeEnvironmentVariables() public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); @@ -229,7 +229,7 @@ public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs( public void LaunchTestHostAsyncShouldNotStartHostProcessIfCancellationTokenIsSet() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); @@ -252,7 +252,7 @@ public void LaunchTestHostShouldLaunchProcessWithEnvironmentVariables() processId.Wait(); Assert.IsTrue(processId.Result); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables)), It.IsAny()), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables))), Times.Once); } [TestMethod] @@ -366,14 +366,14 @@ public async Task LaunchTestHostShouldLaunchProcessWithConnectionInfo() this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); await this.dotnetHostManager.LaunchTestHostAsync(this.defaultTestProcessStartInfo, CancellationToken.None); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs)), It.IsAny()), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs))), Times.Once); } [TestMethod] public void LaunchTestHostShouldSetExitCallBackInCaseCustomHost() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index e994c52a25..3b1051d285 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -993,7 +993,7 @@ public void StartTestRunWithCustomHostShouldComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1004,7 +1004,7 @@ public void StartTestRunWithCustomHostShouldComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1057,7 +1057,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1068,7 +1068,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1107,7 +1107,7 @@ public void StartTestRunWithCustomHostShouldNotAbortAndSendErrorToVstestConsoleI }; var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Throws(new Exception("BadError")); + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Throws(new Exception("BadError")); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1156,7 +1156,7 @@ public async Task StartTestRunAsyncWithCustomHostShouldNotAbortAndSendErrorToVst }; var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Throws(new Exception("BadError")); + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Throws(new Exception("BadError")); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1650,7 +1650,7 @@ public void StartTestRunWithCustomHostWithSelectedTestsComplete() }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1661,7 +1661,7 @@ public void StartTestRunWithCustomHostWithSelectedTestsComplete() It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1712,7 +1712,7 @@ public async Task StartTestRunWithCustomHostAsyncWithSelectedTestsShouldComplete }); var mockLauncher = new Mock(); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())).Callback + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())).Callback (() => this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(testsPayload))); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(runprocessInfoPayload)); @@ -1723,7 +1723,7 @@ public async Task StartTestRunWithCustomHostAsyncWithSelectedTestsShouldComplete It.IsAny(), null, null), Times.Once, "Run Complete must be called"); mockHandler.Verify(mh => mh.HandleTestRunStatsChange(It.IsAny()), Times.Once, "RunChangedArgs must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Once, "TestMessage event must be called"); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Once, "Custom TestHostLauncher must be called"); } [TestMethod] @@ -1747,7 +1747,7 @@ public void StartTestRunWithCustomHostInParallelShouldCallCustomHostMultipleTime var runComplete = CreateMessage(MessageType.ExecutionComplete, completepayload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message1)); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())) + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())) .Callback((startInfo) => { if (startInfo.FileName.Equals(p1.FileName)) @@ -1762,7 +1762,7 @@ public void StartTestRunWithCustomHostInParallelShouldCallCustomHostMultipleTime this.requestSender.InitializeCommunication(); this.requestSender.StartTestRunWithCustomHost(sources, null, new TestPlatformOptions(), mockHandler.Object, mockLauncher.Object); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Exactly(2)); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Exactly(2)); } [TestMethod] @@ -1786,7 +1786,7 @@ public async Task StartTestRunWithCustomHostAsyncInParallelShouldCallCustomHostM var runComplete = CreateMessage(MessageType.ExecutionComplete, completepayload); this.mockCommunicationManager.Setup(cm => cm.ReceiveMessageAsync(It.IsAny())).Returns(Task.FromResult(message1)); - mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny())) + mockLauncher.Setup(ml => ml.LaunchTestHost(It.IsAny())) .Callback((startInfo) => { if (startInfo.FileName.Equals(p1.FileName)) @@ -1802,7 +1802,7 @@ public async Task StartTestRunWithCustomHostAsyncInParallelShouldCallCustomHostM await this.requestSenderAsync.InitializeCommunicationAsync(this.WaitTimeout); await this.requestSenderAsync.StartTestRunWithCustomHostAsync(sources, null, null, mockHandler.Object, mockLauncher.Object); - mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Exactly(2)); + mockLauncher.Verify(ml => ml.LaunchTestHost(It.IsAny()), Times.Exactly(2)); } [TestMethod] From c3dc452ea94e2198bd1bc37b23fdca4eec5c7d44 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Tue, 17 Apr 2018 22:08:43 +0530 Subject: [PATCH 05/16] review comments --- .../DesignMode/DesignModeTestHostLauncher.cs | 2 +- .../DesignMode/IDesignModeClient.cs | 4 +- .../Interfaces/ITestRequestSender.cs | 21 ----- .../TestRequestSender.cs | 18 ----- .../TestRequestSenderTests.cs | 40 +++++----- .../Client/ProxyDiscoveryManagerTests.cs | 24 +++--- .../Client/ProxyExecutionManagerTests.cs | 62 +++++++-------- ...ExecutionManagerWithDataCollectionTests.cs | 19 ----- .../Client/ProxyOperationManagerTests.cs | 24 +++--- .../Hosting/DefaultTestHostManagerTests.cs | 7 +- .../TestRequestManagerTests.cs | 76 ------------------- 11 files changed, 81 insertions(+), 216 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs index 24a74fbf94..bc84515c49 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeTestHostLauncher.cs @@ -3,9 +3,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode { + using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; - using System.Threading; /// /// DesignMode TestHost Launcher for hosting of test process diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs index 1086ab6b32..75daa1eb98 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs @@ -3,10 +3,10 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode { - using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; using System; using System.Threading; + using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; /// /// The interface for design mode client. diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs index 54ce9b5129..2b0f8b5393 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs @@ -26,13 +26,6 @@ public interface ITestRequestSender : IDisposable /// void CheckVersionWithTestHost(); - /// - /// Waits for Request Handler to be connected - /// - /// Time to wait for connection - /// True, if Handler is connected - bool WaitForRequestHandlerConnection(int connectionTimeout); - /// /// Waits for Request Handler to be connected /// @@ -65,13 +58,6 @@ public interface ITestRequestSender : IDisposable /// EventHandler for discovery events void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 discoveryEventsHandler); - /// - /// Starts the TestRun with given sources and criteria - /// - /// RunCriteria for test run - /// EventHandler for test run events - void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler); - /// /// Starts the TestRun with given sources and criteria /// @@ -80,13 +66,6 @@ public interface ITestRequestSender : IDisposable /// Cancellation token void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken); - /// - /// Starts the TestRun with given test cases and criteria - /// - /// RunCriteria for test run - /// EventHandler for test run events - void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler); - /// /// Starts the TestRun with given test cases and criteria /// diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index 7010ae3208..d220e66dd0 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -134,12 +134,6 @@ public int InitializeCommunication() return endpoint.GetIPEndPoint().Port; } - /// - public bool WaitForRequestHandlerConnection(int connectionTimeout) - { - return this.WaitForRequestHandlerConnection(connectionTimeout, CancellationToken.None); - } - /// public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationToken cancellationToken) { @@ -268,12 +262,6 @@ public void InitializeExecution(IEnumerable pathToAdditionalExtensions) this.channel.Send(message); } - /// - public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler) - { - this.StartTestRun(runCriteria, eventHandler, CancellationToken.None); - } - /// public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) { @@ -298,12 +286,6 @@ public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsH this.channel.Send(message); } - /// - public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler) - { - this.StartTestRun(runCriteria, eventHandler, CancellationToken.None); - } - /// public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) { diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs index bb0e9412fa..8b3aaa7012 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs @@ -73,7 +73,7 @@ public void WaitForRequestHandlerConnectionShouldWaitForClientToConnect() { this.SetupFakeCommunicationChannel(); - var connected = this.testRequestSender.WaitForRequestHandlerConnection(1); + var connected = this.testRequestSender.WaitForRequestHandlerConnection(1, It.IsAny()); Assert.IsTrue(connected); } @@ -121,7 +121,7 @@ public void EndSessionShouldNotSendSessionEndMessageIfClientDisconnected() public void EndSessionShouldNotSendSessionEndMessageIfTestHostProcessExited() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.testRequestSender.OnClientProcessExit("Dummy Message"); this.testRequestSender.EndSession(); @@ -428,7 +428,7 @@ public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannel() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DEFAULTPROTOCOLVERSION), Times.Once); this.mockChannel.Verify(mc => mc.Send(It.IsAny()), Times.Once); @@ -439,7 +439,7 @@ public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannelWithVers { this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); } @@ -450,7 +450,7 @@ public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannel( var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DEFAULTPROTOCOLVERSION), Times.Once); this.mockChannel.Verify(mc => mc.Send(It.IsAny()), Times.Once); @@ -462,7 +462,7 @@ public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannelW var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null); this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); - this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); } @@ -473,7 +473,7 @@ public void StartTestRunShouldNotifyRawMessageOnMessageReceived() this.SetupDeserializeMessage(MessageType.TestMessage, new TestMessagePayload()); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("DummyData"), Times.Once); @@ -489,7 +489,7 @@ public void StartTestRunShouldNotifyTestRunStatsChangeOnRunStatsMessageReceived( this.SetupDeserializeMessage(MessageType.TestRunStatsChange, testRunChangedArgs); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunStatsChange(testRunChangedArgs), Times.Once); @@ -507,7 +507,7 @@ public void StartTestRunShouldNotifyExecutionCompleteOnRunCompleteMessageReceive this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify( @@ -531,7 +531,7 @@ public void StartTestRunShouldStopServerOnRunCompleteMessageReceived() this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); @@ -545,7 +545,7 @@ public void StartTestRunShouldNotifyLogMessageOnTestMessageReceived() this.SetupDeserializeMessage(MessageType.TestMessage, testMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Dummy"), Times.Once); @@ -558,7 +558,7 @@ public void StartTestRunShouldNotifyLaunchWithDebuggerOnMessageReceived() this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.LaunchProcessWithDebuggerAttached(launchMessagePayload), Times.Once); @@ -571,7 +571,7 @@ public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceive this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny(), 1), Times.Once); @@ -585,7 +585,7 @@ public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceive this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny(), DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); @@ -597,7 +597,7 @@ public void StartTestRunShouldNotifyLogMessageIfExceptionIsThrownOnMessageReceiv this.SetupExceptionOnMessageReceived(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is(s => s.Contains("Dummy Message"))), Times.Once); @@ -610,7 +610,7 @@ public void StartTestRunShouldNotifyExecutionCompleteIfExceptionIsThrownOnMessag this.SetupExceptionOnMessageReceived(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunComplete(It.Is(t => t.IsAborted), null, null, null), Times.Once); @@ -628,7 +628,7 @@ public void StartTestRunShouldNotNotifyExecutionCompleteIfClientDisconnectedAndO }; this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseMessageReceivedEvent(); // Raise test run complete this.RaiseClientDisconnectedEvent(); @@ -641,7 +641,7 @@ public void StartTestRunShouldNotNotifyExecutionCompleteIfClientDisconnectedAndO public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnected() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseClientDisconnectedEvent(); @@ -654,7 +654,7 @@ public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnected() public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnectedWithClientExit() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.testRequestSender.OnClientProcessExit("Dummy Stderr"); this.RaiseClientDisconnectedEvent(); @@ -668,7 +668,7 @@ public void StartTestRunShouldNotifyExecutionCompleteIfClientDisconnected() { this.SetupOperationAbortedPayload(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); this.RaiseClientDisconnectedEvent(); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyDiscoveryManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyDiscoveryManagerTests.cs index 0ccf548050..2837bf3c8a 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyDiscoveryManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyDiscoveryManagerTests.cs @@ -67,7 +67,7 @@ public void DiscoverTestsShouldNotInitializeExtensionsOnNoExtensions() // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -80,7 +80,7 @@ public void DiscoverTestsShouldNotInitializeExtensionsOnCommunicationFailure() // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); Mock mockTestDiscoveryEventHandler = new Mock(); @@ -96,7 +96,7 @@ public void DiscoverTestsShouldAllowRuntimeProviderToUpdateAdapterSource() TestPluginCache.Instance = null; this.mockTestHostManager.Setup(hm => hm.GetTestSources(this.discoveryCriteria.Sources)).Returns(this.discoveryCriteria.Sources); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestDiscoveryEventHandler = new Mock(); @@ -116,7 +116,7 @@ public void DiscoverTestsShouldUpdateTestSourcesIfSourceDiffersFromTestHostManag this.mockTestHostManager.Setup(hm => hm.GetTestSources(localDiscoveryCriteria.Sources)).Returns(actualSources); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new List()); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestDiscoveryEventHandler = new Mock(); @@ -139,7 +139,7 @@ public void DiscoverTestsShouldNotUpdateTestSourcesIfSourceDoNotDifferFromTestHo this.mockTestHostManager.Setup(hm => hm.GetTestSources(localDiscoveryCriteria.Sources)).Returns(actualSources); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new List()); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestDiscoveryEventHandler = new Mock(); @@ -161,7 +161,7 @@ public void DiscoverTestsShouldNotSendDiscoveryRequestIfCommunicationFails() }) .Returns(Task.FromResult(false)); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; @@ -185,7 +185,7 @@ public void DiscoverTestsShouldInitializeExtensionsIfPresent() // Setup Mocks. TestPluginCacheTests.SetupMockAdditionalPathExtensions(extensions); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new[] { "c:\\e1.dll", "c:\\e2.dll" }); this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -206,7 +206,7 @@ public void DiscoverTestsShouldQueryTestHostManagerForExtensions() try { TestPluginCacheTests.SetupMockAdditionalPathExtensions(new[] { "c:\\e1.dll" }); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new[] { "he1.dll", "c:\\e1.dll" }); this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -227,7 +227,7 @@ public void DiscoverTestsShouldPassAdapterToTestHostManagerFromTestPluginCacheEx TestPluginCache.Instance.UpdateExtensions(new List { "abc.TestAdapter.dll", "xyz.TestAdapter.dll" }, false); try { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); var expectedResult = TestPluginCache.Instance.GetExtensionPaths(string.Empty); this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -256,7 +256,7 @@ public void DiscoverTestsShouldInitializeDefaultAdaptersIfSkipDefaultAdaptersIsF public void DiscoverTestsShouldNotIntializeTestHost() { // Setup mocks. - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); // Act. this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -355,7 +355,7 @@ public void DiscoverTestsShouldCatchExceptionAndCallHandleLogMessageOfError() public void DiscoverTestsShouldInitiateServerDiscoveryLoop() { // Setup mocks. - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); // Act. this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null); @@ -474,7 +474,7 @@ private void InvokeAndVerifyDiscoverTests(bool skipDefaultAdapters) try { this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns((IEnumerable sources, IEnumerable extensions) => extensions); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); var expectedResult = TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.TestAdapterEndsWithPattern, skipDefaultAdapters); this.testDiscoveryManager.Initialize(skipDefaultAdapters); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index 37be35c64a..d286820276 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -65,7 +65,7 @@ public void StartTestRunShouldNotInitializeExtensionsOnNoExtensions() // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, null); @@ -79,7 +79,7 @@ public void StartTestRunShouldAllowRuntimeProviderToUpdateAdapterSource() TestPluginCache.Instance = null; this.mockTestHostManager.Setup(hm => hm.GetTestSources(this.mockTestRunCriteria.Object.Sources)).Returns(this.mockTestRunCriteria.Object.Sources); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestRunEventsHandler = new Mock(); @@ -101,7 +101,7 @@ public void StartTestRunShouldUpdateTestCaseSourceIfTestCaseSourceDiffersFromTes this.mockTestHostManager.Setup(hm => hm.GetTestSources(inputSource)).Returns(actualSources); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new List()); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestRunEventsHandler = new Mock(); this.testExecutionManager.StartTestRun(testRunCriteria, mockTestRunEventsHandler.Object); @@ -123,7 +123,7 @@ public void StartTestRunShouldNotUpdateTestCaseSourceIfTestCaseSourceDoNotDiffer this.mockTestHostManager.Setup(hm => hm.GetTestSources(inputSource)).Returns(actualSources); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(true)); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new List()); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); Mock mockTestRunEventsHandler = new Mock(); this.testExecutionManager.StartTestRun(testRunCriteria, mockTestRunEventsHandler.Object); @@ -138,7 +138,7 @@ public void StartTestRunShouldNotInitializeExtensionsOnCommunicationFailure() // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); Mock mockTestRunEventsHandler = new Mock(); @@ -156,7 +156,7 @@ public void StartTestRunShouldInitializeExtensionsIfPresent() try { var extensions = new List() { "C:\\foo.dll" }; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.mockTestHostManager.Setup(x => x.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())) .Returns(extensions); @@ -177,7 +177,7 @@ public void StartTestRunShouldQueryTestHostManagerForExtensions() TestPluginCache.Instance = null; try { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new[] { "he1.dll", "c:\\e1.dll" }); this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, null); @@ -198,7 +198,7 @@ public void StartTestRunShouldPassAdapterToTestHostManagerFromTestPluginCacheExt TestPluginCache.Instance.UpdateExtensions(new List { "abc.TestAdapter.dll", "xyz.TestAdapter.dll" }, false); try { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); var expectedResult = TestPluginCache.Instance.GetExtensionPaths(string.Empty); this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, null); @@ -226,7 +226,7 @@ public void StartTestRunShouldInitializeDefaultAdaptersIfSkipDefaultAdaptersIsFa [TestMethod] public void StartTestRunShouldIntializeTestHost() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, null); @@ -245,7 +245,7 @@ public void StartTestRunShouldNotSendStartTestRunRequestIfCommunicationFails() }) .Returns(Task.FromResult(false)); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); // Make sure TestPlugincache is refreshed. TestPluginCache.Instance = null; @@ -254,7 +254,7 @@ public void StartTestRunShouldNotSendStartTestRunRequestIfCommunicationFails() this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } [TestMethod] @@ -262,7 +262,7 @@ public void StartTestRunShouldInitializeExtensionsIfTestHostIsNotShared() { TestPluginCache.Instance = null; this.mockTestHostManager.SetupGet(th => th.Shared).Returns(false); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns(new[] { "x.dll" }); this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, null); @@ -273,7 +273,7 @@ public void StartTestRunShouldInitializeExtensionsIfTestHostIsNotShared() [TestMethod] public void SetupChannelShouldThrowExceptionIfClientConnectionTimeout() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); Assert.ThrowsException(() => this.testExecutionManager.SetupChannel(new List { "source.dll" })); @@ -282,7 +282,7 @@ public void SetupChannelShouldThrowExceptionIfClientConnectionTimeout() [TestMethod] public void StartTestRunShouldCatchExceptionAndCallHandleTestRunComplete() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); Mock mockTestRunEventsHandler = new Mock(); @@ -295,7 +295,7 @@ public void StartTestRunShouldCatchExceptionAndCallHandleTestRunComplete() [TestMethod] public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageOfTestRunComplete() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.TestMessage, It.IsAny())).Returns(MessageType.TestMessage); @@ -322,7 +322,7 @@ public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageOfTestRunComp [TestMethod] public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageOfTestMessage() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.TestMessage, It.IsAny())).Returns(MessageType.TestMessage); @@ -349,7 +349,7 @@ public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageOfTestMessage [TestMethod] public void StartTestRunShouldCatchExceptionAndCallHandleLogMessageOfError() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); Mock mockTestRunEventsHandler = new Mock(); @@ -362,7 +362,7 @@ public void StartTestRunShouldCatchExceptionAndCallHandleLogMessageOfError() [TestMethod] public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageAndHandleLogMessage() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny(), It.IsAny())).Returns(Task.FromResult(false)); Mock mockTestRunEventsHandler = new Mock(); @@ -377,10 +377,10 @@ public void StartTestRunShouldCatchExceptionAndCallHandleRawMessageAndHandleLogM public void StartTestRunShouldInitiateTestRunForSourcesThroughTheServer() { TestRunCriteriaWithSources testRunCriteriaPassed = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); - this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager)) + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager, It.IsAny())) .Callback( - (TestRunCriteriaWithSources criteria, ITestRunEventsHandler sink) => + (TestRunCriteriaWithSources criteria, ITestRunEventsHandler sink, CancellationToken cancellationToken) => { testRunCriteriaPassed = criteria; }); @@ -399,10 +399,10 @@ public void StartTestRunShouldInitiateTestRunForSourcesThroughTheServer() public void StartTestRunShouldInitiateTestRunForTestsThroughTheServer() { TestRunCriteriaWithTests testRunCriteriaPassed = null; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); - this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager)) + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager, It.IsAny())) .Callback( - (TestRunCriteriaWithTests criteria, ITestRunEventsHandler sink) => + (TestRunCriteriaWithTests criteria, ITestRunEventsHandler sink, CancellationToken cancellationToken) => { testRunCriteriaPassed = criteria; }); @@ -428,7 +428,7 @@ public void StartTestRunShouldInitiateTestRunForTestsThroughTheServer() [TestMethod] public void CloseShouldSignalToServerSessionEndIfTestHostWasLaunched() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.testExecutionManager.SetupChannel(new List { "source.dll" }); @@ -448,7 +448,7 @@ public void CloseShouldNotSendSignalToServerSessionEndIfTestHostWasNotLaunched() [TestMethod] public void CloseShouldSignalServerSessionEndEachTime() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); this.testExecutionManager.SetupChannel(new List { "source.dll" }); @@ -461,7 +461,7 @@ public void CloseShouldSignalServerSessionEndEachTime() [TestMethod] public void CancelShouldNotSendSendTestRunCancelIfCommunicationFails() { - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); Mock mockTestRunEventsHandler = new Mock(); @@ -477,7 +477,7 @@ public void ExecuteTestsCloseTestHostIfRawMessageIfOfTypeExecutionComplete() { Mock mockTestRunEventsHandler = new Mock(); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.TestMessage, It.IsAny())).Returns(MessageType.TestMessage); this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.ExecutionComplete, It.IsAny())).Returns(MessageType.ExecutionComplete); @@ -504,7 +504,7 @@ public void ExecuteTestsCloseTestHostIfRawMessageIfOfTypeExecutionComplete() public void ExecuteTestsShouldNotCloseTestHostIfRawMessageIsNotOfTypeExecutionComplete() { Mock mockTestRunEventsHandler = new Mock(); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(It.IsAny())).Returns(() => { @@ -573,7 +573,7 @@ public void ExecutionManagerShouldPassOnTestRunStatsChange() public void ExecutionManagerShouldPassOnHandleLogMessage() { Mock mockTestRunEventsHandler = new Mock(); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(false); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(It.IsAny())).Returns(() => { @@ -656,7 +656,7 @@ private void InvokeAndVerifyStartTestRun(bool skipDefaultAdapters) try { this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())).Returns((IEnumerable sources, IEnumerable extensions) => extensions); - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); var expectedResult = TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.TestAdapterEndsWithPattern, skipDefaultAdapters); this.testExecutionManager.Initialize(skipDefaultAdapters); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs index 924036224f..1d6222db82 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerWithDataCollectionTests.cs @@ -112,25 +112,6 @@ public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess StringAssert.Contains(proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2, "MyException"); } - [TestMethod] - public void CancelShouldInvokeAfterTestCaseEnd() - { - this.proxyExecutionManager.Cancel(It.IsAny()); - - this.mockDataCollectionManager.Verify(x => x.AfterTestRunEnd(true, It.IsAny()), Times.Once); - } - - [TestMethod] - public void CancelShouldThrowExceptionIfThrownByProxyDataCollectionManager() - { - this.mockDataCollectionManager.Setup(x => x.AfterTestRunEnd(true, It.IsAny())).Throws(); - - Assert.ThrowsException(() => - { - this.proxyExecutionManager.Cancel(It.IsAny()); - }); - } - [TestMethod] public void UpdateTestProcessStartInfoShouldUpdateDataCollectionPortArg() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index b751ef79f0..34c18c1861 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -51,7 +51,7 @@ public class ProxyOperationManagerTests : ProxyBaseManagerTests public ProxyOperationManagerTests() { this.mockRequestSender = new Mock(); - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(true); this.mockRequestData = new Mock(); this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(new Mock().Object); this.testOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout); @@ -189,7 +189,7 @@ public void SetupChannelShouldWaitForTestHostConnection() { this.testOperationManager.SetupChannel(Enumerable.Empty()); - this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Once); + this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny()), Times.Once); } [TestMethod] @@ -198,7 +198,7 @@ public void SetupChannelShouldNotWaitForTestHostConnectionIfConnectionIsInitiali this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.SetupChannel(Enumerable.Empty()); - this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Exactly(1)); + this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny()), Times.Exactly(1)); } [TestMethod] @@ -206,10 +206,10 @@ public void SetupChannelShouldHonorTimeOutSetByUser() { Environment.SetEnvironmentVariable("VSTEST_CONNECTION_TIMEOUT", "100"); - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(100000)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(100000, It.IsAny())).Returns(true); this.testOperationManager.SetupChannel(Enumerable.Empty()); - this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(100000), Times.Exactly(1)); + this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(100000, It.IsAny()), Times.Exactly(1)); this.connectionTimeout = 400; } @@ -221,14 +221,14 @@ public void SetupChannelShouldNotHonorGarbageTimeOutSetByUser() this.testOperationManager.SetupChannel(Enumerable.Empty()); - this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout), Times.Exactly(1)); + this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny()), Times.Exactly(1)); } [TestMethod] public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() { SetupTestHostLaunched(true); - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(false); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout); @@ -239,7 +239,7 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() public void SetupChannelShouldThrowIfLaunchTestHostFails() { SetupTestHostLaunched(false); - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(true); var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout); @@ -288,7 +288,7 @@ public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredTrueShould [TestMethod] public void CloseShouldEndSessionIfHostWasLaunched() { - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(true); this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); @@ -316,7 +316,7 @@ public void CloseShouldAlwaysCleanTestHost() public void CloseShouldResetChannelInitialization() { this.SetupWaitForTestHostExit(); - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(true); this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); @@ -329,12 +329,12 @@ public void CloseShouldResetChannelInitialization() public void CloseShouldTerminateTesthostProcessIfWaitTimesout() { // Ensure testhost start returns a dummy process id - this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout)).Returns(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(true); this.testOperationManager.SetupChannel(Enumerable.Empty()); this.testOperationManager.Close(); - this.mockTestHostManager.Verify(th => th.CleanTestHostAsync(CancellationToken.None), Times.Once); + this.mockTestHostManager.Verify(th => th.CleanTestHostAsync(It.IsAny()), Times.Once); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 9ce2d94750..578e0f706d 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -365,17 +365,16 @@ public void DefaultTestHostManagerShouldBeShared() [TestMethod] public void LaunchTestHostShouldUseCustomHostIfSet() { - System.Diagnostics.Debugger.Launch(); var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); this.testHostManager.HostLaunched += this.TestHostManagerHostLaunched; Task pid = this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None); pid.Wait(); - mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny()), Times.Once); + mockCustomLauncher.Verify(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny()), Times.Once); Assert.IsTrue(pid.Result); Assert.AreEqual(currentProcess.Id, this.testHostId); @@ -387,7 +386,7 @@ public void LaunchTestHostShouldSetExitCallbackInCaseCustomHost() var mockCustomLauncher = new Mock(); this.testHostManager.SetCustomLauncher(mockCustomLauncher.Object); var currentProcess = Process.GetCurrentProcess(); - mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny())).Returns(currentProcess.Id); + mockCustomLauncher.Setup(mc => mc.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(currentProcess.Id); this.testHostManager.LaunchTestHostAsync(this.startInfo, CancellationToken.None).Wait(); this.mockProcessHelper.Verify(ph => ph.SetExitCallback(currentProcess.Id, It.IsAny>())); diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index e535e4eb1d..a986fd330e 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -814,44 +814,6 @@ public void DiscoverTestsShouldPublishMetrics() this.mockMetricsPublisher.Verify(mp => mp.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, It.IsAny>()), Times.Once); } - [TestMethod] - public void CancelTestRunShouldWaitForCreateTestRunRequest() - { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a", "b" }, - RunSettings = DefaultRunsettings - }; - - bool createTestRunRequestCalled = false; - bool cancelCalledPostTestRunRequest = false; - - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria testRunCriteria, TestPlatformOptions options) => - { - createTestRunRequestCalled = true; - }).Returns(mockRunRequest.Object); - - // Run request should not complete before the abort - mockRunRequest.Setup(mr => mr.WaitForCompletion(It.IsAny())).Callback(() => { Thread.Sleep(20); }); - - mockRunRequest.Setup(mr => mr.CancelAsync()).Callback(() => - { - cancelCalledPostTestRunRequest = createTestRunRequestCalled; - }); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var cancelTask = Task.Run(() => this.testRequestManager.CancelTestRun()); - var runTask = Task.Run(() => this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig)); - - Task.WaitAll(cancelTask, runTask); - - Assert.IsTrue(cancelCalledPostTestRunRequest, "CancelRequest must execute after create run request"); - } - [TestMethod] public void CancelShouldNotThrowExceptionIfTestRunRequestHasBeenDisposed() { @@ -884,44 +846,6 @@ public void AbortShouldNotThrowExceptionIfTestRunRequestHasBeenDisposed() this.testRequestManager.AbortTestRun(); } - [TestMethod] - public void AbortTestRunShouldWaitForCreateTestRunRequest() - { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a", "b" }, - RunSettings = DefaultRunsettings - }; - - bool createTestRunRequestCalled = false; - bool abortCalledPostTestRunRequest = false; - - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria testRunCriteria, TestPlatformOptions options) => - { - createTestRunRequestCalled = true; - }).Returns(mockRunRequest.Object); - - // Run request should not complete before the abort - mockRunRequest.Setup(mr => mr.WaitForCompletion(It.IsAny())).Callback(() => { Thread.Sleep(20); }); - - mockRunRequest.Setup(mr => mr.Abort()).Callback(() => - { - abortCalledPostTestRunRequest = createTestRunRequestCalled; - }); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var cancelTask = Task.Run(() => this.testRequestManager.AbortTestRun()); - var runTask = Task.Run(() => this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig)); - - Task.WaitAll(cancelTask, runTask); - - Assert.IsTrue(abortCalledPostTestRunRequest, "Abort Request must execute after create run request"); - } - [TestMethod] public void RunTestsShouldReadTheBatchSizeFromSettingsAndSetItForTestRunCriteria() { From 7674f35aa858b6e7c6f5df4687133ad5dcc7df38 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Wed, 18 Apr 2018 12:58:51 +0530 Subject: [PATCH 06/16] Unit tests --- .../DesignMode/DesignModeClientTests.cs | 13 +++ .../DataCollectionRequestSenderTests.cs | 62 ++++++++++++++ .../TestRequestSenderTests.cs | 11 +++ .../Client/ProxyExecutionManagerTests.cs | 82 +++++++++++++++++++ .../Client/ProxyOperationManagerTests.cs | 24 ++++++ ...DataCollectionTestRunEventsHandlerTests.cs | 39 +++++++++ 6 files changed, 231 insertions(+) create mode 100644 test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestSenderTests.cs diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 2f721d6acd..264fd29bc6 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -312,6 +312,19 @@ public void DesignModeClientLaunchCustomHostMustThrowIfInvalidAckComes() testableDesignModeClient.LaunchCustomHost(info, CancellationToken.None); } + [TestMethod] + [ExpectedException(typeof(OperationCanceledException))] + public void DesignModeClientLaunchCustomHostMustThrowIfCancellationOccursBeforeHostLaunch() + { + var testableDesignModeClient = new TestableDesignModeClient(this.mockCommunicationManager.Object, JsonDataSerializer.Instance, this.mockPlatformEnvrironment.Object); + + var info = new TestProcessStartInfo(); + var cancellationTokenSource = new CancellationTokenSource(); + cancellationTokenSource.Cancel(); + + testableDesignModeClient.LaunchCustomHost(info, cancellationTokenSource.Token); + } + [TestMethod] public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnExceptionInDiscovery() { diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestSenderTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestSenderTests.cs new file mode 100644 index 0000000000..b9e7ac208e --- /dev/null +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestSenderTests.cs @@ -0,0 +1,62 @@ +// 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.TestPlatform.CommunicationUtilities.UnitTests +{ + using System; + using System.Collections.ObjectModel; + + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; + + [TestClass] + public class DataCollectionRequestSenderTests + { + private Mock mockCommunicationManager; + private DataCollectionRequestSender requestSender; + private Mock mockDataSerializer; + + public DataCollectionRequestSenderTests() + { + this.mockCommunicationManager = new Mock(); + this.mockDataSerializer = new Mock(); + this.requestSender = new DataCollectionRequestSender(this.mockCommunicationManager.Object, this.mockDataSerializer.Object); + } + + [TestMethod] + public void SendAfterTestRunStartAndGetResultShouldReturnAttachments() + { + var datacollectorUri = new Uri("my://custom/datacollector"); + var attachmentUri = new Uri("my://filename.txt"); + var displayName = "CustomDataCollector"; + var attachment = new AttachmentSet(datacollectorUri, displayName); + attachment.Attachments.Add(new UriDataAttachment(attachmentUri, "filename.txt")); + + this.mockDataSerializer.Setup(x => x.DeserializePayload>(It.IsAny())).Returns(new Collection() { attachment }); + this.mockCommunicationManager.Setup(x => x.ReceiveMessage()).Returns(new Message() { MessageType = MessageType.AfterTestRunEndResult, Payload = null }); + + var attachmentSets = this.requestSender.SendAfterTestRunStartAndGetResult(null, false); + + Assert.IsNotNull(attachmentSets); + Assert.AreEqual(attachmentSets.Count, 1); + Assert.IsNotNull(attachmentSets[0]); + Assert.AreEqual(attachmentSets[0].DisplayName, displayName); + Assert.AreEqual(datacollectorUri, attachmentSets[0].Uri); + Assert.AreEqual(attachmentUri, attachmentSets[0].Attachments[0].Uri); + } + + [TestMethod] + public void SendAfterTestRunStartAndGetResultShouldNotReturnAttachmentsWhenRequestCancelled() + { + var attachmentSets = this.requestSender.SendAfterTestRunStartAndGetResult(null, true); + + Assert.IsNull(attachmentSets); + } + } +} diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs index 8b3aaa7012..dc05ce9cc3 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs @@ -78,6 +78,17 @@ public void WaitForRequestHandlerConnectionShouldWaitForClientToConnect() Assert.IsTrue(connected); } + [TestMethod] + public void WaitForRequestHandlerConnectionWithInfiniteTimeoutShouldReturnImmediatelyWhenCancellationRequested() + { + var cancellationTokenSource = new CancellationTokenSource(); + cancellationTokenSource.Cancel(); + + var connected = this.testRequestSender.WaitForRequestHandlerConnection(-1, cancellationTokenSource.Token); + + Assert.IsFalse(connected); + } + [TestMethod] public void CloseShouldCallStopServerOnCommunicationManager() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index d286820276..394d15c2c5 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -171,6 +171,60 @@ public void StartTestRunShouldInitializeExtensionsIfPresent() } } + [TestMethod] + public void StartTestRunShouldNotInvokeRequestSenderMethodsIfRequestCancelled() + { + // Make sure TestPlugincache is refreshed. + TestPluginCache.Instance = null; + + try + { + var extensions = new List() { "C:\\foo.dll" }; + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); + this.mockTestHostManager.Setup(x => x.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())) + .Returns(extensions); + var mockTestRunEventsHandler = new Mock(); + + this.testExecutionManager.Cancel(null); + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + finally + { + TestPluginCache.Instance = null; + } + } + + [TestMethod] + public void StartTestRunShouldThrowIfRequestAborted() + { + // Make sure TestPlugincache is refreshed. + TestPluginCache.Instance = null; + + try + { + var extensions = new List() { "C:\\foo.dll" }; + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); + this.mockTestHostManager.Setup(x => x.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())) + .Returns(extensions); + var mockTestRunEventsHandler = new Mock(); + + this.testExecutionManager.Abort(null); + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + finally + { + TestPluginCache.Instance = null; + } + } + [TestMethod] public void StartTestRunShouldQueryTestHostManagerForExtensions() { @@ -472,6 +526,34 @@ public void CancelShouldNotSendSendTestRunCancelIfCommunicationFails() this.mockRequestSender.Verify(s => s.SendTestRunCancel(), Times.Never); } + [TestMethod] + public void AbortShouldSendTestRunAbortIfCommunicationSuccessful() + { + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); + + Mock mockTestRunEventsHandler = new Mock(); + + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + this.testExecutionManager.Abort(It.IsAny()); + + this.mockRequestSender.Verify(s => s.SendTestRunAbort(), Times.Once); + } + + [TestMethod] + public void AbortShouldNotSendTestRunAbortIfCommunicationFails() + { + this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(false); + + Mock mockTestRunEventsHandler = new Mock(); + + this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); + + this.testExecutionManager.Abort(It.IsAny()); + + this.mockRequestSender.Verify(s => s.SendTestRunAbort(), Times.Never); + } + [TestMethod] public void ExecuteTestsCloseTestHostIfRawMessageIfOfTypeExecutionComplete() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 34c18c1861..c5996f0590 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -235,6 +235,20 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); } + [TestMethod] + public void SetupChannelShouldThrowIfRequestCancelled() + { + SetupTestHostLaunched(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); + + var cancellationTokenSource = new CancellationTokenSource(); + var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, this.connectionTimeout, cancellationTokenSource); + + cancellationTokenSource.Cancel(); + + Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); + } + [TestMethod] public void SetupChannelShouldThrowIfLaunchTestHostFails() { @@ -459,6 +473,16 @@ public TestableProxyOperationManager( int clientConnectionTimeout) : base(requestData, requestSender, testHostManager, clientConnectionTimeout) { } + + public TestableProxyOperationManager( + IRequestData requestData, + ITestRequestSender requestSender, + ITestRuntimeProvider testHostManager, + int clientConnectionTimeout, + CancellationTokenSource cancellationTokenSource) : base(requestData, requestSender, testHostManager, clientConnectionTimeout) + { + this.CancellationTokenSource = cancellationTokenSource; + } } private class TestableDotnetTestHostManager : DotnetTestHostManager diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs index 7411276528..9335de51be 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/DataCollection/DataCollectionTestRunEventsHandlerTests.cs @@ -66,6 +66,45 @@ public void HandleRawMessageShouldGetDataCollectorAttachments() Times.Once); } + [TestMethod] + public void HandleRawMessageShouldInvokeAfterTestRunEndPassingFalseIfRequestNotCancelled() + { + var testRunCompleteEventArgs = new TestRunCompleteEventArgs(null, false, false, null, new Collection(), new TimeSpan()); + + this.mockDataSerializer.Setup(x => x.DeserializeMessage(It.IsAny())).Returns(new Message() { MessageType = MessageType.ExecutionComplete }); + this.mockDataSerializer.Setup(x => x.DeserializePayload(It.IsAny())) + .Returns(new TestRunCompletePayload() { TestRunCompleteArgs = testRunCompleteEventArgs }); + + var cancellationTokenSource = new CancellationTokenSource(); + testRunEventHandler = new DataCollectionTestRunEventsHandler(this.baseTestRunEventsHandler.Object, this.proxyDataCollectionManager.Object, cancellationTokenSource.Token, this.mockDataSerializer.Object); + + testRunEventHandler.HandleRawMessage(string.Empty); + + this.proxyDataCollectionManager.Verify( + dcm => dcm.AfterTestRunEnd(false, It.IsAny()), + Times.Once); + } + + [TestMethod] + public void HandleRawMessageShouldInvokeAfterTestRunEndPassingTrueIfRequestCancelled() + { + var testRunCompleteEventArgs = new TestRunCompleteEventArgs(null, false, false, null, new Collection(), new TimeSpan()); + + this.mockDataSerializer.Setup(x => x.DeserializeMessage(It.IsAny())).Returns(new Message() { MessageType = MessageType.ExecutionComplete }); + this.mockDataSerializer.Setup(x => x.DeserializePayload(It.IsAny())) + .Returns(new TestRunCompletePayload() { TestRunCompleteArgs = testRunCompleteEventArgs }); + + var cancellationTokenSource = new CancellationTokenSource(); + testRunEventHandler = new DataCollectionTestRunEventsHandler(this.baseTestRunEventsHandler.Object, this.proxyDataCollectionManager.Object, cancellationTokenSource.Token, this.mockDataSerializer.Object); + cancellationTokenSource.Cancel(); + + testRunEventHandler.HandleRawMessage(string.Empty); + + this.proxyDataCollectionManager.Verify( + dcm => dcm.AfterTestRunEnd(true, It.IsAny()), + Times.Once); + } + #region Get Combined Attachments [TestMethod] public void GetCombinedAttachmentSetsShouldReturnCombinedAttachments() From 046c86aefe6ea464fdceb66f8b4f7280813dd0dd Mon Sep 17 00:00:00 2001 From: abhishkk Date: Thu, 19 Apr 2018 17:07:54 +0530 Subject: [PATCH 07/16] review comments --- .../DesignMode/DesignModeClient.cs | 6 +-- .../Execution/TestRunRequest.cs | 7 +-- .../TestRequestSender.cs | 8 +--- .../Client/ProxyOperationManager.cs | 39 ++++++++-------- .../Hosting/DotnetTestHostManager.cs | 8 ++-- .../Client/ProxyOperationManagerTests.cs | 45 +++++++++++++------ .../Hosting/DotnetTestHostManagerTests.cs | 8 ++-- 7 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index e27fd1e975..ab2c6f31f8 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -253,9 +253,6 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat waitHandle.Set(); }; - // Registering cancellationToken to set waitHandle (whenever request is cancelled). - var cancellationTokenRegistration = cancellationToken.Register(() => waitHandle.Set()); - this.communicationManager.SendMessage(MessageType.CustomTestHostLaunch, testProcessStartInfo); // LifeCycle of the TP through DesignModeClient is maintained by the IDEs or user-facing-clients like LUTs, who call TestPlatform @@ -263,9 +260,8 @@ public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo, Cancellat // Even if TP has a timeout here, there is no way TP can abort or stop the thread/task that is hung in IDE or LUT // Even if TP can abort the API somehow, TP is essentially putting IDEs or Clients in inconsistent state without having info on // Since the IDEs own user-UI-experience here, TP will let the custom host launch as much time as IDEs define it for their users - waitHandle.WaitOne(); + WaitHandle.WaitAny(new WaitHandle[] { waitHandle, cancellationToken.WaitHandle }); - cancellationTokenRegistration.Dispose(); cancellationToken.ThrowIfCancellationRequested(); this.onAckMessageReceived = null; diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index 9f1e92a732..a58438532a 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -46,11 +46,6 @@ public class TestRunRequest : ITestRunRequest, ITestRunEventsHandler /// private object cancelSyncObject = new Object(); - /// - /// Sync object for abort operation - /// - private object abortSyncObject = new Object(); - /// /// The run completion event which will be signalled on completion of test run. /// @@ -275,7 +270,7 @@ public void Abort() { EqtTrace.Verbose("TestRunRequest.Abort: Aborting."); - lock (this.abortSyncObject) + lock (this.cancelSyncObject) { if (this.disposed) { diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index 32817e054c..043f4b029f 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -137,14 +137,12 @@ public int InitializeCommunication() /// public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationToken cancellationToken) { - var cancellationTokenRegistration = cancellationToken.Register(() => this.connected.Set()); if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose("TestRequestSender.WaitForRequestHandlerConnection: waiting for connection with timeout: {0}", connectionTimeout); } - var waitSuccess = this.connected.Wait(connectionTimeout) && !cancellationToken.IsCancellationRequested; - cancellationTokenRegistration.Dispose(); + var waitSuccess = this.connected.Wait(connectionTimeout, cancellationToken) && !cancellationToken.IsCancellationRequested; return waitSuccess; } @@ -547,7 +545,6 @@ private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Excepti private string GetAbortErrorMessage(Exception exception, bool getClientError, CancellationToken cancellationToken) { - var cancellationTokenRegistration = cancellationToken.Register(() => this.clientExited.Set()); EqtTrace.Verbose("TestRequestSender: GetAbortErrorMessage: Exception: " + exception); // It is also possible for an operation to abort even if client has not @@ -560,7 +557,7 @@ private string GetAbortErrorMessage(Exception exception, bool getClientError, Ca // Set a default message and wait for test host to exit for a moment reason = CommonResources.UnableToCommunicateToTestHost; - if (this.clientExited.Wait(this.clientExitedWaitTime) && !cancellationToken.IsCancellationRequested) + if (this.clientExited.Wait(this.clientExitedWaitTime, cancellationToken) && !cancellationToken.IsCancellationRequested) { EqtTrace.Info("TestRequestSender: GetAbortErrorMessage: Received test host error message."); reason = this.clientExitErrorMessage; @@ -571,7 +568,6 @@ private string GetAbortErrorMessage(Exception exception, bool getClientError, Ca } } - cancellationTokenRegistration.Dispose(); return reason; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 5906bea78c..02d05e1628 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -99,7 +99,6 @@ protected ProxyOperationManager(IRequestData requestData, ITestRequestSender req /// public virtual bool SetupChannel(IEnumerable sources) { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); var connTimeout = EnvironmentHelper.GetConnectionTimeout(); if (!this.initialized) @@ -126,7 +125,7 @@ public virtual bool SetupChannel(IEnumerable sources) try { // Launch the test host. - this.testHostLaunched = this.LaunchTestHostAsync(testHostStartInfo, this.CancellationTokenSource.Token); + this.testHostLaunched = this.LaunchTestHost(testHostStartInfo, this.CancellationTokenSource.Token); if (this.testHostLaunched && testHostConnectionInfo.Role == ConnectionRole.Host) { @@ -176,24 +175,6 @@ public virtual bool SetupChannel(IEnumerable sources) return true; } - private bool LaunchTestHostAsync(TestProcessStartInfo testHostStartInfo, CancellationToken token) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - return this.testHostManager.LaunchTestHostAsync(testHostStartInfo, token).Result; - } - - private bool WaitForRequestHandlerConnection(int connTimeout) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - return this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token); - } - - private void CheckVersionWithTestHost() - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.CheckVersionWithTestHost(); - } - /// /// Closes the channel, terminate test host process. /// @@ -346,5 +327,23 @@ private void ThrowExceptionOnConnectionFailure(int connTimeout) throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, errorMsg)); } + + private bool LaunchTestHost(TestProcessStartInfo testHostStartInfo, CancellationToken token) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + return this.testHostManager.LaunchTestHostAsync(testHostStartInfo, token).Result; + } + + private bool WaitForRequestHandlerConnection(int connTimeout) + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + return this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token); + } + + private void CheckVersionWithTestHost() + { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); + this.RequestSender.CheckVersionWithTestHost(); + } } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 295bb9934e..824a17208c 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -52,7 +52,7 @@ public class DotnetTestHostManager : ITestRuntimeProvider private IFileHelper fileHelper; - private ITestHostLauncher testHostLauncher; + private ITestHostLauncher customTestHostLauncher; private Process testHostProcess; @@ -144,7 +144,7 @@ public void Initialize(IMessageLogger logger, string runsettingsXml) /// public void SetCustomLauncher(ITestHostLauncher customLauncher) { - this.testHostLauncher = customLauncher; + this.customTestHostLauncher = customLauncher; } /// @@ -329,7 +329,7 @@ private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToke try { this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); - if (this.testHostLauncher == null) + if (this.customTestHostLauncher == null) { EqtTrace.Verbose("DotnetTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); @@ -338,7 +338,7 @@ private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToke } else { - var processId = this.testHostLauncher.LaunchTestHost(testHostStartInfo); + var processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); this.testHostProcess = Process.GetProcessById(processId); this.processHelper.SetExitCallback(processId, this.ExitCallBack); } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 0c87af7e10..aec6a3d2d2 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -52,6 +52,9 @@ public class ProxyOperationManagerTests : ProxyBaseManagerTests private static readonly string TimoutErrorMessage = "vstest.console process failed to connect to testhost process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout."; + private static readonly string OperationCanceledMessage = + @"System.OperationCanceledException: The operation was canceled"; + public ProxyOperationManagerTests() { this.mockRequestSender = new Mock(); @@ -234,6 +237,35 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() Assert.AreEqual(message, ProxyOperationManagerTests.TimoutErrorMessage); } + [TestMethod] + public void SetupChannelShouldThrowIfRequestCancelled() + { + SetupTestHostLaunched(true); + + var cancellationTokenSource = new CancellationTokenSource(); + var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); + + cancellationTokenSource.Cancel(); + var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; + Assert.IsTrue(message.Contains(ProxyOperationManagerTests.OperationCanceledMessage)); + } + + [TestMethod] + public void SetupChannelShouldNotCallRequestSenderMethodsIfRequestCancelled() + { + SetupTestHostLaunched(true); + + var cancellationTokenSource = new CancellationTokenSource(); + var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); + + cancellationTokenSource.Cancel(); + var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; + + this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Never); + this.mockTestHostManager.Verify(thm => thm.LaunchTestHostAsync(It.IsAny(), It.IsAny()), Times.Never); + } + [TestMethod] public void SetupChannelShouldThrowIfLaunchTestHostFails() { @@ -437,19 +469,6 @@ private void SetUpMocksForDotNetTestHost() }).Returns(Process.GetCurrentProcess()); } - //private void SetupChannelMessage(string messageType, string returnMessageType, TPayload returnPayload) - //{ - // this.mockChannel.Setup(mc => mc.Send(It.Is(s => s.Contains(messageType)))) - // .Callback(() => this.mockChannel.Raise(c => c.MessageReceived += null, this.mockChannel.Object, new MessageReceivedEventArgs { Data = messageType })); - - // this.mockDataSerializer.Setup(ds => ds.SerializePayload(It.Is(s => s.Equals(messageType)), It.IsAny())).Returns(messageType); - // this.mockDataSerializer.Setup(ds => ds.SerializePayload(It.Is(s => s.Equals(messageType)), It.IsAny(), It.IsAny())).Returns(messageType); - // this.mockDataSerializer.Setup(ds => ds.DeserializeMessage(It.Is(s => s.Equals(messageType)))) - // .Returns(new Message { MessageType = returnMessageType }); - // this.mockDataSerializer.Setup(ds => ds.DeserializePayload(It.Is(m => m.MessageType.Equals(messageType)))) - // .Returns(returnPayload); - //} - private class TestableProxyOperationManager : ProxyOperationManager { public TestableProxyOperationManager(IRequestData requestData, diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 409e683868..285dcda804 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -211,7 +211,7 @@ public void GetTestHostProcessStartInfoShouldIncludeEnvironmentVariables() public void LaunchTestHostShouldLaunchProcessWithNullEnvironmentVariablesOrArgs() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); @@ -252,7 +252,7 @@ public void LaunchTestHostShouldLaunchProcessWithEnvironmentVariables() processId.Wait(); Assert.IsTrue(processId.Result); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables))), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.EnvironmentVariables.Equals(variables)), It.IsAny()), Times.Once); } [TestMethod] @@ -366,14 +366,14 @@ public async Task LaunchTestHostShouldLaunchProcessWithConnectionInfo() this.dotnetHostManager.SetCustomLauncher(this.mockTestHostLauncher.Object); await this.dotnetHostManager.LaunchTestHostAsync(this.defaultTestProcessStartInfo, CancellationToken.None); - this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs))), Times.Once); + this.mockTestHostLauncher.Verify(thl => thl.LaunchTestHost(It.Is(x => x.Arguments.Equals(expectedArgs)), It.IsAny()), Times.Once); } [TestMethod] public void LaunchTestHostShouldSetExitCallBackInCaseCustomHost() { var expectedProcessId = Process.GetCurrentProcess().Id; - this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny())).Returns(expectedProcessId); + this.mockTestHostLauncher.Setup(thl => thl.LaunchTestHost(It.IsAny(), It.IsAny())).Returns(expectedProcessId); this.mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); var startInfo = this.GetDefaultStartInfo(); From e206964d3e3a7f56f455795797121a94f1128468 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Thu, 19 Apr 2018 17:08:22 +0530 Subject: [PATCH 08/16] resolve conflict --- .../Client/ProxyOperationManagerTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index aec6a3d2d2..5563836666 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -481,8 +481,7 @@ public TestableProxyOperationManager( IRequestData requestData, ITestRequestSender requestSender, ITestRuntimeProvider testHostManager, - int clientConnectionTimeout, - CancellationTokenSource cancellationTokenSource) : base(requestData, requestSender, testHostManager, clientConnectionTimeout) + CancellationTokenSource cancellationTokenSource) : base(requestData, requestSender, testHostManager) { this.CancellationTokenSource = cancellationTokenSource; } From 3015b3e3001f626791c1d14dba8483f9ad5034d8 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 09:54:50 +0530 Subject: [PATCH 09/16] Passing operation canceled instead of test platform exception to translation layer. --- .../Hosting/DefaultTestHostManager.cs | 31 +++++++------------ .../Hosting/DotnetTestHostManager.cs | 27 ++++++---------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 868edd4ec8..3d4e8fedcd 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -369,30 +369,21 @@ private void OnHostExited(HostProviderEventArgs e) private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken) { - try - { - this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); - EqtTrace.Verbose("Launching default test Host Process {0} with arguments {1}", testHostStartInfo.FileName, testHostStartInfo.Arguments); + this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); + EqtTrace.Verbose("Launching default test Host Process {0} with arguments {1}", testHostStartInfo.FileName, testHostStartInfo.Arguments); - if (this.customTestHostLauncher == null) - { - EqtTrace.Verbose("DefaultTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); + if (this.customTestHostLauncher == null) + { + EqtTrace.Verbose("DefaultTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); - cancellationToken.ThrowIfCancellationRequested(); - this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; - } - else - { - int processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); - this.testHostProcess = Process.GetProcessById(processId); - this.processHelper.SetExitCallback(processId, this.ExitCallBack); - } + cancellationToken.ThrowIfCancellationRequested(); + this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; } - catch (OperationCanceledException ex) + else { - EqtTrace.Error("DefaultTestHostManager.LaunchHost: Failed to launch testhost: {0}", ex); - this.messageLogger.SendMessage(TestMessageLevel.Error, ex.ToString()); - return false; + int processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); + this.testHostProcess = Process.GetProcessById(processId); + this.processHelper.SetExitCallback(processId, this.ExitCallBack); } this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched", 0, this.testHostProcess.Id)); diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 824a17208c..2f7150244d 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -326,28 +326,19 @@ private void OnHostExited(HostProviderEventArgs e) private bool LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken) { - try + this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); + if (this.customTestHostLauncher == null) { - this.testHostProcessStdError = new StringBuilder(this.ErrorLength, this.ErrorLength); - if (this.customTestHostLauncher == null) - { - EqtTrace.Verbose("DotnetTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); + EqtTrace.Verbose("DotnetTestHostManager: Starting process '{0}' with command line '{1}'", testHostStartInfo.FileName, testHostStartInfo.Arguments); - cancellationToken.ThrowIfCancellationRequested(); - this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; - } - else - { - var processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); - this.testHostProcess = Process.GetProcessById(processId); - this.processHelper.SetExitCallback(processId, this.ExitCallBack); - } + cancellationToken.ThrowIfCancellationRequested(); + this.testHostProcess = this.processHelper.LaunchProcess(testHostStartInfo.FileName, testHostStartInfo.Arguments, testHostStartInfo.WorkingDirectory, testHostStartInfo.EnvironmentVariables, this.ErrorReceivedCallback, this.ExitCallBack) as Process; } - catch (OperationCanceledException ex) + else { - EqtTrace.Error("DotnetTestHostManager.LaunchHost: Failed to launch testhost: {0}", ex); - this.messageLogger.SendMessage(TestMessageLevel.Error, ex.ToString()); - return false; + var processId = this.customTestHostLauncher.LaunchTestHost(testHostStartInfo, cancellationToken); + this.testHostProcess = Process.GetProcessById(processId); + this.processHelper.SetExitCallback(processId, this.ExitCallBack); } this.OnHostLaunched(new HostProviderEventArgs("Test Runtime launched", 0, this.testHostProcess.Id)); From 4513b144f4ead4489a6980b3cbb0a2eebc71a1b0 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 20:00:50 +0530 Subject: [PATCH 10/16] review comments --- .../Interfaces/ITestRequestSender.cs | 4 +- .../TestRequestSender.cs | 31 +++++++-------- .../Client/ProxyExecutionManager.cs | 4 +- .../TestRequestSenderTests.cs | 38 +++++++++---------- .../Client/ProxyExecutionManagerTests.cs | 18 ++++----- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs index 2b0f8b5393..6abee2b829 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs @@ -64,7 +64,7 @@ public interface ITestRequestSender : IDisposable /// RunCriteria for test run /// EventHandler for test run events /// Cancellation token - void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken); + void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler); /// /// Starts the TestRun with given test cases and criteria @@ -72,7 +72,7 @@ public interface ITestRequestSender : IDisposable /// RunCriteria for test run /// EventHandler for test run events /// Cancellation token - void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken); + void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler); /// /// Ends the Session diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index 043f4b029f..ba5747d764 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -142,9 +142,10 @@ public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationT EqtTrace.Verbose("TestRequestSender.WaitForRequestHandlerConnection: waiting for connection with timeout: {0}", connectionTimeout); } - var waitSuccess = this.connected.Wait(connectionTimeout, cancellationToken) && !cancellationToken.IsCancellationRequested; + var waitIndex = WaitHandle.WaitAny(new WaitHandle[] { this.connected.WaitHandle, cancellationToken.WaitHandle }, connectionTimeout); - return waitSuccess; + // Return true if wait is not because of cancellation or connection timeout. + return waitIndex != 1 && waitIndex != WaitHandle.WaitTimeout; } /// @@ -262,14 +263,14 @@ public void InitializeExecution(IEnumerable pathToAdditionalExtensions) } /// - public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) + public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler) { this.messageEventHandler = eventHandler; this.onDisconnected = (disconnectedEventArgs) => { - this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true, cancellationToken); + this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true); }; - this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler, cancellationToken); + this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler); this.channel.MessageReceived += this.onMessageReceived; var message = this.dataSerializer.SerializePayload( @@ -286,14 +287,14 @@ public void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsH } /// - public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler, CancellationToken cancellationToken) + public void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler) { this.messageEventHandler = eventHandler; this.onDisconnected = (disconnectedEventArgs) => { - this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true, cancellationToken); + this.OnTestRunAbort(eventHandler, disconnectedEventArgs.Error, true); }; - this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler, cancellationToken); + this.onMessageReceived = (sender, args) => this.OnExecutionMessageReceived(sender, args, eventHandler); this.channel.MessageReceived += this.onMessageReceived; var message = this.dataSerializer.SerializePayload( @@ -382,7 +383,7 @@ public void Dispose() this.communicationEndpoint.Stop(); } - private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs messageReceived, ITestRunEventsHandler testRunEventsHandler, CancellationToken cancellationToken) + private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs messageReceived, ITestRunEventsHandler testRunEventsHandler) { try { @@ -437,7 +438,7 @@ private void OnExecutionMessageReceived(object sender, MessageReceivedEventArgs } catch (Exception exception) { - this.OnTestRunAbort(testRunEventsHandler, exception, false, cancellationToken); + this.OnTestRunAbort(testRunEventsHandler, exception, false); } } @@ -488,7 +489,7 @@ private void OnDiscoveryMessageReceived(ITestDiscoveryEventsHandler2 discoveryEv } } - private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exception exception, bool getClientError, CancellationToken cancellationToken) + private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exception exception, bool getClientError) { if (this.IsOperationComplete()) { @@ -499,7 +500,7 @@ private void OnTestRunAbort(ITestRunEventsHandler testRunEventsHandler, Exceptio EqtTrace.Verbose("TestRequestSender: OnTestRunAbort: Set operation complete."); this.SetOperationComplete(); - var reason = this.GetAbortErrorMessage(exception, getClientError, cancellationToken); + var reason = this.GetAbortErrorMessage(exception, getClientError); EqtTrace.Error("TestRequestSender: Aborting test run because {0}", reason); this.LogErrorMessage(string.Format(CommonResources.AbortedTestRun, reason)); @@ -525,7 +526,7 @@ private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Excepti this.SetOperationComplete(); var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(-1, true); - var reason = this.GetAbortErrorMessage(exception, getClientError, CancellationToken.None); + var reason = this.GetAbortErrorMessage(exception, getClientError); EqtTrace.Error("TestRequestSender: Aborting test discovery because {0}", reason); this.LogErrorMessage(string.Format(CommonResources.AbortedTestDiscovery, reason)); @@ -543,7 +544,7 @@ private void OnDiscoveryAbort(ITestDiscoveryEventsHandler2 eventHandler, Excepti eventHandler.HandleDiscoveryComplete(discoveryCompleteEventArgs, null); } - private string GetAbortErrorMessage(Exception exception, bool getClientError, CancellationToken cancellationToken) + private string GetAbortErrorMessage(Exception exception, bool getClientError) { EqtTrace.Verbose("TestRequestSender: GetAbortErrorMessage: Exception: " + exception); @@ -557,7 +558,7 @@ private string GetAbortErrorMessage(Exception exception, bool getClientError, Ca // Set a default message and wait for test host to exit for a moment reason = CommonResources.UnableToCommunicateToTestHost; - if (this.clientExited.Wait(this.clientExitedWaitTime, cancellationToken) && !cancellationToken.IsCancellationRequested) + if (this.clientExited.Wait(this.clientExitedWaitTime)) { EqtTrace.Info("TestRequestSender: GetAbortErrorMessage: Received test host error message."); reason = this.clientExitErrorMessage; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index 9479bd2f01..df7fff4123 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -265,13 +265,13 @@ private void InitializeExtensions(IEnumerable sources) private void StartTestRunWithTests(TestRunCriteriaWithTests runRequest, ProxyExecutionManager proxyExecutionManager) { this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.StartTestRun(runRequest, this, this.CancellationTokenSource.Token); + this.RequestSender.StartTestRun(runRequest, this); } private void StartTestRunWithSources(TestRunCriteriaWithSources runRequest, ProxyExecutionManager proxyExecutionManager) { this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.StartTestRun(runRequest, this, this.CancellationTokenSource.Token); + this.RequestSender.StartTestRun(runRequest, this); } } } diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs index 14099b6987..9dad040c56 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestRequestSenderTests.cs @@ -139,7 +139,7 @@ public void EndSessionShouldNotSendSessionEndMessageIfClientDisconnected() public void EndSessionShouldNotSendSessionEndMessageIfTestHostProcessExited() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.testRequestSender.OnClientProcessExit("Dummy Message"); this.testRequestSender.EndSession(); @@ -458,7 +458,7 @@ public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannel() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DEFAULTPROTOCOLVERSION), Times.Once); this.mockChannel.Verify(mc => mc.Send(It.IsAny()), Times.Once); @@ -469,7 +469,7 @@ public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannelWithVers { this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); } @@ -480,7 +480,7 @@ public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannel( var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DEFAULTPROTOCOLVERSION), Times.Once); this.mockChannel.Verify(mc => mc.Send(It.IsAny()), Times.Once); @@ -492,7 +492,7 @@ public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannelW var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null); this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); - this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object); this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); } @@ -503,7 +503,7 @@ public void StartTestRunShouldNotifyRawMessageOnMessageReceived() this.SetupDeserializeMessage(MessageType.TestMessage, new TestMessagePayload()); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("DummyData"), Times.Once); @@ -519,7 +519,7 @@ public void StartTestRunShouldNotifyTestRunStatsChangeOnRunStatsMessageReceived( this.SetupDeserializeMessage(MessageType.TestRunStatsChange, testRunChangedArgs); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunStatsChange(testRunChangedArgs), Times.Once); @@ -537,7 +537,7 @@ public void StartTestRunShouldNotifyExecutionCompleteOnRunCompleteMessageReceive this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify( @@ -561,7 +561,7 @@ public void StartTestRunShouldStopServerOnRunCompleteMessageReceived() this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); @@ -575,7 +575,7 @@ public void StartTestRunShouldNotifyLogMessageOnTestMessageReceived() this.SetupDeserializeMessage(MessageType.TestMessage, testMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Dummy"), Times.Once); @@ -588,7 +588,7 @@ public void StartTestRunShouldNotifyLaunchWithDebuggerOnMessageReceived() this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.LaunchProcessWithDebuggerAttached(launchMessagePayload), Times.Once); @@ -601,7 +601,7 @@ public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceive this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny(), 1), Times.Once); @@ -615,7 +615,7 @@ public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceive this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION); this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny(), DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once); @@ -627,7 +627,7 @@ public void StartTestRunShouldNotifyLogMessageIfExceptionIsThrownOnMessageReceiv this.SetupExceptionOnMessageReceived(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is(s => s.Contains("Dummy Message"))), Times.Once); @@ -640,7 +640,7 @@ public void StartTestRunShouldNotifyExecutionCompleteIfExceptionIsThrownOnMessag this.SetupExceptionOnMessageReceived(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunComplete(It.Is(t => t.IsAborted), null, null, null), Times.Once); @@ -658,7 +658,7 @@ public void StartTestRunShouldNotNotifyExecutionCompleteIfClientDisconnectedAndO }; this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseMessageReceivedEvent(); // Raise test run complete this.RaiseClientDisconnectedEvent(); @@ -671,7 +671,7 @@ public void StartTestRunShouldNotNotifyExecutionCompleteIfClientDisconnectedAndO public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnected() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseClientDisconnectedEvent(); @@ -684,7 +684,7 @@ public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnected() public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnectedWithClientExit() { this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.testRequestSender.OnClientProcessExit("Dummy Stderr"); this.RaiseClientDisconnectedEvent(); @@ -698,7 +698,7 @@ public void StartTestRunShouldNotifyExecutionCompleteIfClientDisconnected() { this.SetupOperationAbortedPayload(); this.SetupFakeCommunicationChannel(); - this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object, CancellationToken.None); + this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object); this.RaiseClientDisconnectedEvent(); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index a10a0c4ec7..ae2426fca9 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -185,8 +185,8 @@ public void StartTestRunShouldNotInvokeRequestSenderMethodsIfRequestCancelled() this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); } finally { @@ -212,8 +212,8 @@ public void StartTestRunShouldThrowIfRequestAborted() this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); } finally { @@ -304,7 +304,7 @@ public void StartTestRunShouldNotSendStartTestRunRequestIfCommunicationFails() this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); } [TestMethod] @@ -428,9 +428,9 @@ public void StartTestRunShouldInitiateTestRunForSourcesThroughTheServer() { TestRunCriteriaWithSources testRunCriteriaPassed = null; this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); - this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager, It.IsAny())) + this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager)) .Callback( - (TestRunCriteriaWithSources criteria, ITestRunEventsHandler sink, CancellationToken cancellationToken) => + (TestRunCriteriaWithSources criteria, ITestRunEventsHandler sink) => { testRunCriteriaPassed = criteria; }); @@ -450,9 +450,9 @@ public void StartTestRunShouldInitiateTestRunForTestsThroughTheServer() { TestRunCriteriaWithTests testRunCriteriaPassed = null; this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); - this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager, It.IsAny())) + this.mockRequestSender.Setup(s => s.StartTestRun(It.IsAny(), this.testExecutionManager)) .Callback( - (TestRunCriteriaWithTests criteria, ITestRunEventsHandler sink, CancellationToken cancellationToken) => + (TestRunCriteriaWithTests criteria, ITestRunEventsHandler sink) => { testRunCriteriaPassed = criteria; }); From 3a7711446167a01493268cb5433db8cd0f87e3a6 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 20:04:17 +0530 Subject: [PATCH 11/16] review comments --- .../Interfaces/ITestRequestSender.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs index 6abee2b829..d65aa7bb0f 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestSender.cs @@ -63,7 +63,6 @@ public interface ITestRequestSender : IDisposable /// /// RunCriteria for test run /// EventHandler for test run events - /// Cancellation token void StartTestRun(TestRunCriteriaWithSources runCriteria, ITestRunEventsHandler eventHandler); /// @@ -71,7 +70,6 @@ public interface ITestRequestSender : IDisposable /// /// RunCriteria for test run /// EventHandler for test run events - /// Cancellation token void StartTestRun(TestRunCriteriaWithTests runCriteria, ITestRunEventsHandler eventHandler); /// From 07f8abde60a6a17e0dc80ecea783b83d9900e1b3 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 20:11:54 +0530 Subject: [PATCH 12/16] review comments --- .../TestRequestSender.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs index ba5747d764..89c4b222d0 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/TestRequestSender.cs @@ -144,8 +144,8 @@ public bool WaitForRequestHandlerConnection(int connectionTimeout, CancellationT var waitIndex = WaitHandle.WaitAny(new WaitHandle[] { this.connected.WaitHandle, cancellationToken.WaitHandle }, connectionTimeout); - // Return true if wait is not because of cancellation or connection timeout. - return waitIndex != 1 && waitIndex != WaitHandle.WaitTimeout; + // Return true if wait is because of waitHandle. + return waitIndex == 0; } /// From b11ac54a3daa919143dd2844a1bee9149336009c Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 20:43:36 +0530 Subject: [PATCH 13/16] review comments --- .../Client/ProxyExecutionManager.cs | 26 ++++----- .../Client/ProxyOperationManager.cs | 26 ++------- .../Client/ProxyExecutionManagerTests.cs | 54 ------------------- .../Client/ProxyOperationManagerTests.cs | 16 ------ 4 files changed, 16 insertions(+), 106 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index df7fff4123..2e8313bc97 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -106,6 +106,15 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH if (this.isCommunicationEstablished) { + if (this.CancellationTokenSource.IsCancellationRequested) + { + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("ProxyExecutionManager.StartTestRun: Canceling the current run after getting cancelation request."); + } + throw new TestPlatformException(Resources.Resources.CancelationRequested); + } + this.InitializeExtensions(testPackages); // This code should be in sync with InProcessProxyExecutionManager.StartTestRun executionContext @@ -127,12 +136,12 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH if (testRunCriteria.HasSpecificSources) { var runRequest = testRunCriteria.CreateTestRunCriteriaForSources(testHostManager, runsettings, executionContext, testPackages); - this.StartTestRunWithSources(runRequest, this); + this.RequestSender.StartTestRun(runRequest, this); } else { var runRequest = testRunCriteria.CreateTestRunCriteriaForTests(testHostManager, runsettings, executionContext, testPackages); - this.StartTestRunWithTests(runRequest, this); + this.RequestSender.StartTestRun(runRequest, this); } } } @@ -250,7 +259,6 @@ private void LogMessage(TestMessageLevel testMessageLevel, string message) private void InitializeExtensions(IEnumerable sources) { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); var extensions = TestPluginCache.Instance.GetExtensionPaths(TestPlatformConstants.TestAdapterEndsWithPattern, this.skipDefaultAdapters); var sourceList = sources.ToList(); var platformExtensions = this.testHostManager.GetTestPlatformExtensions(sourceList, extensions).ToList(); @@ -261,17 +269,5 @@ private void InitializeExtensions(IEnumerable sources) this.RequestSender.InitializeExecution(platformExtensions); } } - - private void StartTestRunWithTests(TestRunCriteriaWithTests runRequest, ProxyExecutionManager proxyExecutionManager) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.StartTestRun(runRequest, this); - } - - private void StartTestRunWithSources(TestRunCriteriaWithSources runRequest, ProxyExecutionManager proxyExecutionManager) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.StartTestRun(runRequest, this); - } } } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 02d05e1628..223da01501 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -99,6 +99,7 @@ protected ProxyOperationManager(IRequestData requestData, ITestRequestSender req /// public virtual bool SetupChannel(IEnumerable sources) { + this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); var connTimeout = EnvironmentHelper.GetConnectionTimeout(); if (!this.initialized) @@ -125,7 +126,8 @@ public virtual bool SetupChannel(IEnumerable sources) try { // Launch the test host. - this.testHostLaunched = this.LaunchTestHost(testHostStartInfo, this.CancellationTokenSource.Token); + var hostLaunchedTask = this.testHostManager.LaunchTestHostAsync(testHostStartInfo, this.CancellationTokenSource.Token); + this.testHostLaunched = hostLaunchedTask.Result; if (this.testHostLaunched && testHostConnectionInfo.Role == ConnectionRole.Host) { @@ -154,7 +156,7 @@ public virtual bool SetupChannel(IEnumerable sources) // Wait for a timeout for the client to connect. if (!this.testHostLaunched || - !this.WaitForRequestHandlerConnection(connTimeout * 1000)) + !this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token)) { this.ThrowExceptionOnConnectionFailure(connTimeout); } @@ -166,7 +168,7 @@ public virtual bool SetupChannel(IEnumerable sources) if (this.versionCheckRequired) { - this.CheckVersionWithTestHost(); + this.RequestSender.CheckVersionWithTestHost(); } this.initialized = true; @@ -327,23 +329,5 @@ private void ThrowExceptionOnConnectionFailure(int connTimeout) throw new TestPlatformException(string.Format(CultureInfo.CurrentUICulture, errorMsg)); } - - private bool LaunchTestHost(TestProcessStartInfo testHostStartInfo, CancellationToken token) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - return this.testHostManager.LaunchTestHostAsync(testHostStartInfo, token).Result; - } - - private bool WaitForRequestHandlerConnection(int connTimeout) - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - return this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token); - } - - private void CheckVersionWithTestHost() - { - this.CancellationTokenSource.Token.ThrowIfCancellationRequested(); - this.RequestSender.CheckVersionWithTestHost(); - } } } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs index ae2426fca9..2c77a6a5d2 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyExecutionManagerTests.cs @@ -167,60 +167,6 @@ public void StartTestRunShouldInitializeExtensionsIfPresent() } } - [TestMethod] - public void StartTestRunShouldNotInvokeRequestSenderMethodsIfRequestCancelled() - { - // Make sure TestPlugincache is refreshed. - TestPluginCache.Instance = null; - - try - { - var extensions = new List() { "C:\\foo.dll" }; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); - this.mockTestHostManager.Setup(x => x.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())) - .Returns(extensions); - var mockTestRunEventsHandler = new Mock(); - - this.testExecutionManager.Cancel(null); - this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); - - this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); - } - finally - { - TestPluginCache.Instance = null; - } - } - - [TestMethod] - public void StartTestRunShouldThrowIfRequestAborted() - { - // Make sure TestPlugincache is refreshed. - TestPluginCache.Instance = null; - - try - { - var extensions = new List() { "C:\\foo.dll" }; - this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny())).Returns(true); - this.mockTestHostManager.Setup(x => x.GetTestPlatformExtensions(It.IsAny>(), It.IsAny>())) - .Returns(extensions); - var mockTestRunEventsHandler = new Mock(); - - this.testExecutionManager.Abort(null); - this.testExecutionManager.StartTestRun(this.mockTestRunCriteria.Object, mockTestRunEventsHandler.Object); - - this.mockRequestSender.Verify(s => s.InitializeExecution(extensions), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); - this.mockRequestSender.Verify(s => s.StartTestRun(It.IsAny(), It.IsAny()), Times.Never); - } - finally - { - TestPluginCache.Instance = null; - } - } - [TestMethod] public void StartTestRunShouldQueryTestHostManagerForExtensions() { diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 5563836666..56c760c947 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -250,22 +250,6 @@ public void SetupChannelShouldThrowIfRequestCancelled() Assert.IsTrue(message.Contains(ProxyOperationManagerTests.OperationCanceledMessage)); } - [TestMethod] - public void SetupChannelShouldNotCallRequestSenderMethodsIfRequestCancelled() - { - SetupTestHostLaunched(true); - - var cancellationTokenSource = new CancellationTokenSource(); - var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); - - cancellationTokenSource.Cancel(); - var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; - - this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(It.IsAny(), It.IsAny()), Times.Never); - this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Never); - this.mockTestHostManager.Verify(thm => thm.LaunchTestHostAsync(It.IsAny(), It.IsAny()), Times.Never); - } - [TestMethod] public void SetupChannelShouldThrowIfLaunchTestHostFails() { From 93923a24811bf0d6668a1d709d581fe523ee3c3c Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 21:07:30 +0530 Subject: [PATCH 14/16] unit tests fix --- .../Client/ProxyOperationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 223da01501..567999ef3d 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -156,7 +156,7 @@ public virtual bool SetupChannel(IEnumerable sources) // Wait for a timeout for the client to connect. if (!this.testHostLaunched || - !this.RequestSender.WaitForRequestHandlerConnection(connTimeout, this.CancellationTokenSource.Token)) + !this.RequestSender.WaitForRequestHandlerConnection(connTimeout * 1000, this.CancellationTokenSource.Token)) { this.ThrowExceptionOnConnectionFailure(connTimeout); } From 24bd93373b16e70d5939af0aa06388f156001659 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 21:09:18 +0530 Subject: [PATCH 15/16] unit tests fail --- .../Client/ProxyOperationManagerTests.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 56c760c947..64d2cbf867 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -52,9 +52,6 @@ public class ProxyOperationManagerTests : ProxyBaseManagerTests private static readonly string TimoutErrorMessage = "vstest.console process failed to connect to testhost process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout."; - private static readonly string OperationCanceledMessage = - @"System.OperationCanceledException: The operation was canceled"; - public ProxyOperationManagerTests() { this.mockRequestSender = new Mock(); @@ -246,8 +243,7 @@ public void SetupChannelShouldThrowIfRequestCancelled() var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource); cancellationTokenSource.Cancel(); - var message = Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())).Message; - Assert.IsTrue(message.Contains(ProxyOperationManagerTests.OperationCanceledMessage)); + Assert.ThrowsException(() => operationManager.SetupChannel(Enumerable.Empty())); } [TestMethod] From 08975c618531e9053532b571386b3a456f367f74 Mon Sep 17 00:00:00 2001 From: abhishkk Date: Fri, 20 Apr 2018 21:43:08 +0530 Subject: [PATCH 16/16] unit tests --- .../Client/ProxyOperationManagerTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs index 64d2cbf867..e6457a5eae 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/ProxyOperationManagerTests.cs @@ -238,6 +238,7 @@ public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut() public void SetupChannelShouldThrowIfRequestCancelled() { SetupTestHostLaunched(true); + this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny())).Returns(false); var cancellationTokenSource = new CancellationTokenSource(); var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource);