From 6189eb0a906e403807890e61b9f6d72faf27a376 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 2 Jun 2020 10:50:13 +0200 Subject: [PATCH] More changes --- .../DesignMode/DesignModeClient.cs | 2 +- .../Messages/MessageType.cs | 9 +++- .../EventHandlers/TestRequestHandler.cs | 2 +- .../ITranslationLayerRequestSender.cs | 5 ++ .../Interfaces/IVsTestConsoleWrapper2.cs | 5 ++ .../VsTestConsoleRequestSender.cs | 12 ++++- .../VsTestConsoleWrapper.cs | 6 +++ .../EventHandler/RunEventHandler.cs | 4 +- .../FinalizeMultiTestRunsTests.cs | 51 +++++++------------ 9 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 056c992f08..c8522992b0 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -201,7 +201,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) break; } - case MessageType.MultiTestRunsFinalization: + case MessageType.MultiTestRunsFinalizationStart: { var multiTestRunsFinalizationPayload = this.communicationManager.DeserializePayload(message); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs index a5af0cd46a..041617694f 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Messages/MessageType.cs @@ -126,12 +126,17 @@ public static class MessageType /// /// Multi test runs finalization /// - public const string MultiTestRunsFinalization = "TestExecution.MultiTestRunsFinalization"; + public const string MultiTestRunsFinalizationStart = "MultiTestRunsFinalization.Start"; /// /// Multi test runs finalization callback /// - public const string MultiTestRunsFinalizationComplete = "TestExecution.MultiTestRunsFinalizationComplete"; + public const string MultiTestRunsFinalizationComplete = "MultiTestRunsFinalization.Complete"; + + /// + /// Cancel multi test runs finalization + /// + public const string MultiTestRunsFinalizationCancel = "MultiTestRunsFinalization.Cancel"; /// /// Extensions Initialization diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs index 18759177dd..05a3fed45b 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/EventHandlers/TestRequestHandler.cs @@ -375,7 +375,7 @@ public void OnMessageReceived(object sender, MessageReceivedEventArgs messageRec break; } - case MessageType.MultiTestRunsFinalization: + case MessageType.MultiTestRunsFinalizationStart: { EqtTrace.Info("Multi test runs finalization started."); var multiTestRunsFinalizationEventsHandler = new MultiTestRunsFinalizationEventsHandler(this); diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs index a8e73ab57c..9c19766e17 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/ITranslationLayerRequestSender.cs @@ -117,5 +117,10 @@ internal interface ITranslationLayerRequestSender : IDisposable /// List of attachements /// void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + + /// + /// Cancels multi test runs finalization + /// + void CancelMultiTestRunsFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs index 9988ed548a..5fbc6ce412 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapper2.cs @@ -19,5 +19,10 @@ public interface IVsTestConsoleWrapper2 : IVsTestConsoleWrapper /// List of attachements /// EventHandler to receive session complete event void FinalizeMultiTestRuns(ICollection attachments, IMultiTestRunsFinalizationEventsHandler multiTestRunsFinalizationCompleteEventsHandler); + + /// + /// Cancel last multi test runs finalization + /// + void CancelMultiTestRunsFinalization(); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs index b01516f499..e546068396 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleRequestSender.cs @@ -389,6 +389,16 @@ public void FinalizeMultiTestRuns(ICollection attachments, IMulti this.SendMessageAndListenAndReportAttachements(attachments, testSessionEventsHandler); } + /// + public void CancelMultiTestRunsFinalization() + { + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("VsTestConsoleRequestSender.CancelMultiTestRunsFinalization: Canceling multi test runs finalization."); + } + this.communicationManager.SendMessage(MessageType.MultiTestRunsFinalizationCancel); + } + /// /// Closes the communication channel /// @@ -739,7 +749,7 @@ private void SendMessageAndListenAndReportAttachements(ICollection attachments, IMulti this.requestSender.FinalizeMultiTestRuns(attachments, testSessionEventsHandler); } + /// + public void CancelMultiTestRunsFinalization() + { + throw new System.NotImplementedException(); + } + #endregion private void EnsureInitialized() diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs index 6b694e29a9..c4bd80e385 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs @@ -75,9 +75,9 @@ public void HandleTestRunComplete( this.TestResults.AddRange(lastChunkArgs.NewTestResults); } - if(runContextAttachments != null) + if (testRunCompleteArgs.AttachmentSets != null) { - this.Attachments.AddRange(runContextAttachments); + this.Attachments.AddRange(testRunCompleteArgs.AttachmentSets); } this.Metrics = testRunCompleteArgs.Metrics; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs index 8cfb2c1a99..bb26430a8b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/FinalizeMultiTestRunsTests.cs @@ -39,47 +39,24 @@ public void Cleanup() this.vstestConsoleWrapper?.EndSession(); } - //[TestMethod] - //[NetFullTargetFrameworkDataSource] - //[NetCoreTargetFrameworkDataSource] - //public void RunAllTests(RunnerInfo runnerInfo) - //{ - // AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); - // this.Setup(); - - // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - // this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - - // // Assert - // Assert.AreEqual(6, this.runEventHandler.TestResults.Count); - // Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - // Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); - - // this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); - // Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); - //} - [TestMethod] - public void RunAllTests() + [NetFullTargetFrameworkDataSource] + [NetCoreTargetFrameworkDataSource] + public void FinalizeMultiTestRuns(RunnerInfo runnerInfo) { - RunnerInfo runnerInfo = new RunnerInfo(AcceptanceTestBase.DesktopTargetFramework, AcceptanceTestBase.DesktopTargetFramework); AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); - //this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); // Assert - Assert.AreEqual(3, this.runEventHandler.TestResults.Count); - Assert.AreEqual(1, this.runEventHandler.Attachments.Count); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - //Assert.AreEqual(2, this.runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Skipped)); - - //this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); - //Assert.AreEqual(1, this.multiTestRunsFinalizationEventHandler.Attachments.Count); + Assert.AreEqual(testEnvironment.RunnerFramework.Equals(IntegrationTestBase.DesktopRunnerFramework) ? 1 : 2, this.multiTestRunsFinalizationEventHandler.Attachments.Count); } [TestMethod] @@ -92,7 +69,13 @@ public void EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runnerInfo AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo); this.Setup(); - this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies(), this.GetDefaultRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Take(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + this.vstestConsoleWrapper.RunTests(this.GetTestAssemblies().Skip(1), this.GetCodeCoverageRunSettings(), this.runEventHandler); + + Assert.AreEqual(6, this.runEventHandler.TestResults.Count); + Assert.AreEqual(2, this.runEventHandler.Attachments.Count); + + this.vstestConsoleWrapper.FinalizeMultiTestRuns(runEventHandler.Attachments, multiTestRunsFinalizationEventHandler); this.vstestConsoleWrapper?.EndSession(); // Assert