From 66f48fa3808c6823c9de75a7966bc8f19c485687 Mon Sep 17 00:00:00 2001 From: samadala Date: Thu, 10 Nov 2016 18:09:20 +0530 Subject: [PATCH 1/2] Fix for testcasefilter is not working for netcore --- .../Parallel/ParallelProxyExecutionManager.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs index bace7ebb9e..6d6ce0e87c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs @@ -270,7 +270,16 @@ private bool StartTestRunOnConcurrentManager(IProxyExecutionManager proxyExecuti { EqtTrace.Info("ProxyParallelExecutionManager: Triggering test run for next source: {0}", nextSource); - testRunCriteria = new TestRunCriteria(new List() { nextSource }, this.actualTestRunCriteria.FrequencyOfRunStatsChangeEvent, this.actualTestRunCriteria.KeepAlive, this.actualTestRunCriteria.TestRunSettings, this.actualTestRunCriteria.RunStatsChangeEventTimeout, this.actualTestRunCriteria.TestHostLauncher); + testRunCriteria = new TestRunCriteria( + new List() { nextSource }, + this.actualTestRunCriteria.FrequencyOfRunStatsChangeEvent, + this.actualTestRunCriteria.KeepAlive, + this.actualTestRunCriteria.TestRunSettings, + this.actualTestRunCriteria.RunStatsChangeEventTimeout, + this.actualTestRunCriteria.TestHostLauncher) + { + TestCaseFilter = this.actualTestRunCriteria.TestCaseFilter + }; } } else @@ -281,7 +290,12 @@ private bool StartTestRunOnConcurrentManager(IProxyExecutionManager proxyExecuti EqtTrace.Info("ProxyParallelExecutionManager: Triggering test run for next source: {0}", nextSetOfTests?.FirstOrDefault()?.Source); testRunCriteria = new TestRunCriteria( - nextSetOfTests, this.actualTestRunCriteria.FrequencyOfRunStatsChangeEvent, this.actualTestRunCriteria.KeepAlive, this.actualTestRunCriteria.TestRunSettings, this.actualTestRunCriteria.RunStatsChangeEventTimeout, this.actualTestRunCriteria.TestHostLauncher); + nextSetOfTests, + this.actualTestRunCriteria.FrequencyOfRunStatsChangeEvent, + this.actualTestRunCriteria.KeepAlive, + this.actualTestRunCriteria.TestRunSettings, + this.actualTestRunCriteria.RunStatsChangeEventTimeout, + this.actualTestRunCriteria.TestHostLauncher); } } From 49e57881ee549460fa9456aa15c7f541e6ba8547 Mon Sep 17 00:00:00 2001 From: samadala Date: Mon, 14 Nov 2016 11:31:14 +0530 Subject: [PATCH 2/2] Update unittests --- .../Client/TestRunCriteria.cs | 120 +++++++++++++++--- .../ParallelProxyExecutionManagerTests.cs | 51 +++++--- 2 files changed, 132 insertions(+), 39 deletions(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/TestRunCriteria.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/TestRunCriteria.cs index ecf1391f71..3386e4f83c 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/TestRunCriteria.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/TestRunCriteria.cs @@ -20,7 +20,7 @@ public class TestRunCriteria : BaseTestRunCriteria, ITestRunConfiguration private string testCaseFilter; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -34,7 +34,7 @@ public TestRunCriteria(IEnumerable sources, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -51,7 +51,7 @@ public TestRunCriteria(IEnumerable sources, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -71,7 +71,7 @@ public TestRunCriteria(IEnumerable sources, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -94,7 +94,7 @@ public TestRunCriteria(IEnumerable sources, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Create the TestRunCriteria for a test run /// /// @@ -114,7 +114,7 @@ public TestRunCriteria(IEnumerable sources, BaseTestRunCriteria baseTest } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -151,7 +151,7 @@ public TestRunCriteria( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -186,7 +186,7 @@ public TestRunCriteria( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Tests which should be executed @@ -200,7 +200,7 @@ public TestRunCriteria(IEnumerable tests, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Tests which should be executed @@ -217,7 +217,7 @@ public TestRunCriteria(IEnumerable tests, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Tests which should be executed @@ -237,7 +237,7 @@ public TestRunCriteria(IEnumerable tests, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Tests which should be executed @@ -260,7 +260,7 @@ public TestRunCriteria(IEnumerable tests, long frequencyOfRunStatsChan } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Tests which should be executed @@ -278,7 +278,7 @@ public TestRunCriteria(IEnumerable tests, BaseTestRunCriteria baseTest } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// Sources which contains tests that should be executed @@ -330,7 +330,7 @@ public IEnumerable Sources public Dictionary> AdapterSourceMap { get; private set; } /// - /// Gets the tests that need to executed in this test run. + /// Gets the tests that need to executed in this test run. /// This will be null if test run is created with specific test containers /// [DataMember] @@ -393,6 +393,46 @@ public override string ToString() return sb.ToString(); } + + protected bool Equals(TestRunCriteria other) + { + return base.Equals(other) + && string.Equals(this.testCaseFilter, other.testCaseFilter); + } + + /// + public override bool Equals(object obj) + { + if (object.ReferenceEquals(null, obj)) + { + return false; + } + + if (object.ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return this.Equals((TestRunCriteria)obj); + } + + /// + public override int GetHashCode() + { + unchecked + { + int hashCode = base.GetHashCode(); + hashCode = (hashCode * 397) ^ (this.testCaseFilter != null ? this.testCaseFilter.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (this.AdapterSourceMap != null ? this.AdapterSourceMap.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (this.Tests != null ? this.Tests.GetHashCode() : 0); + return hashCode; + } + } } /// @@ -535,14 +575,14 @@ public BaseTestRunCriteria(long frequencyOfRunStatsChangeEvent, bool keepAlive, public ITestHostLauncher TestHostLauncher { get; private set; } /// - /// Gets the frequency of run stats test event. + /// Gets the frequency of run stats test event. /// /// - /// Run stats change event will be raised after completion of these number of tests. - /// Note that this event is raised asynchronously and the underlying execution process is not - /// paused during the listener invocation. So if the event handler, you try to query the + /// Run stats change event will be raised after completion of these number of tests. + /// Note that this event is raised asynchronously and the underlying execution process is not + /// paused during the listener invocation. So if the event handler, you try to query the /// next set of results, you may get more than 'FrequencyOfRunStatsChangeEvent'. - /// + /// [DataMember] public long FrequencyOfRunStatsChangeEvent { get; private set; } @@ -551,5 +591,47 @@ public BaseTestRunCriteria(long frequencyOfRunStatsChangeEvent, bool keepAlive, /// [DataMember] public TimeSpan RunStatsChangeEventTimeout { get; private set; } + + protected bool Equals(BaseTestRunCriteria other) + { + return this.KeepAlive == other.KeepAlive + && string.Equals(this.TestRunSettings, other.TestRunSettings) + && this.FrequencyOfRunStatsChangeEvent == other.FrequencyOfRunStatsChangeEvent + && this.RunStatsChangeEventTimeout.Equals(other.RunStatsChangeEventTimeout); + } + + /// + public override bool Equals(object obj) + { + if (object.ReferenceEquals(null, obj)) + { + return false; + } + + if (object.ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != this.GetType()) + { + return false; + } + + return this.Equals((BaseTestRunCriteria)obj); + } + + /// + public override int GetHashCode() + { + unchecked + { + var hashCode = this.KeepAlive.GetHashCode(); + hashCode = (hashCode * 397) ^ (this.TestRunSettings != null ? this.TestRunSettings.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ this.FrequencyOfRunStatsChangeEvent.GetHashCode(); + hashCode = (hashCode * 397) ^ this.RunStatsChangeEventTimeout.GetHashCode(); + return hashCode; + } + } } } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs index e9c1d0d433..f49d53d37c 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Client/Parallel/ParallelProxyExecutionManagerTests.cs @@ -2,22 +2,21 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Client { + using System; using System.Collections.Generic; + using System.Collections.ObjectModel; using System.Linq; using System.Threading; using System.Threading.Tasks; + using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; - using System; - using System.Collections.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; - [TestClass] public class ParallelProxyExecutionManagerTests { @@ -104,13 +103,13 @@ public void StartTestRunShouldProcessAllSources() return manager.Object; }; - proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); + this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); var mockHandler = new Mock(); var sources = new List() { "1.dll", "2.dll" }; - var testRunCriteria = new TestRunCriteria(sources, 100); + var testRunCriteria = new TestRunCriteria(sources, 100) { TestCaseFilter = "Name~Test" }; var processedSources = new List(); var syncObject = new object(); @@ -127,10 +126,20 @@ public void StartTestRunShouldProcessAllSources() Task.Delay(100).Wait(); + // Duplicated testRunCriteria should match the actual one. + Assert.AreEqual(testRunCriteria, criteria, "Mismastch in testRunCriteria"); + handler.HandleTestRunComplete( - new TestRunCompleteEventArgs(new TestRunStatistics(new Dictionary()) - , false, false, null, null, TimeSpan.Zero) - , null, null, null); + new TestRunCompleteEventArgs( + new TestRunStatistics(new Dictionary()), + false, + false, + null, + null, + TimeSpan.Zero), + null, + null, + null); }); } @@ -146,7 +155,7 @@ public void StartTestRunShouldProcessAllSources() completeEvent.Set(); }); - proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); + this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); completeEvent.WaitOne(); Assert.AreEqual(sources.Count, processedSources.Count, "All Sources must be processed."); @@ -166,7 +175,6 @@ public void StartTestRunShouldProcessAllSources() Assert.IsTrue(matchFound, "Concurrency issue detected: Source['{0}'] did NOT get processed at all", source); } - } [TestMethod] @@ -181,7 +189,7 @@ public void StartTestRunShouldProcessAllTestCases() return manager.Object; }; - proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 3); + this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 3); var mockHandler = new Mock(); @@ -210,6 +218,9 @@ public void StartTestRunShouldProcessAllTestCases() Task.Delay(100).Wait(); + // Duplicated testRunCriteria should match the actual one. + Assert.AreEqual(testRunCriteria, criteria, "Mismastch in testRunCriteria"); + handler.HandleTestRunComplete( new TestRunCompleteEventArgs(new TestRunStatistics(new Dictionary()) , false, false, null, null, TimeSpan.Zero) @@ -229,7 +240,7 @@ public void StartTestRunShouldProcessAllTestCases() completeEvent.Set(); }); - proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); + this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); completeEvent.WaitOne(); Assert.AreEqual(tests.Count, processedTestCases.Count, "All Tests must be processed."); @@ -265,7 +276,7 @@ public void StartTestRunWithSourcesShouldNotSendCompleteUntilAllSourcesAreProces return manager.Object; }; - proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); + this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); var mockHandler = new Mock(); @@ -310,7 +321,7 @@ public void StartTestRunWithSourcesShouldNotSendCompleteUntilAllSourcesAreProces Task.Run(() => { - proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); + this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); }); eventHandle.WaitOne(); @@ -348,7 +359,7 @@ public void StartTestRunWithTestsShouldNotSendCompleteUntilAllTestsAreProcessed( return manager.Object; }; - proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 3); + this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 3); var mockHandler = new Mock(); @@ -399,7 +410,7 @@ public void StartTestRunWithTestsShouldNotSendCompleteUntilAllTestsAreProcessed( Task.Run(() => { - proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); + this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); }); eventHandle.WaitOne(); @@ -437,7 +448,7 @@ public void StartTestRunShouldAggregateRunData() return manager.Object; }; - proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); + this.proxyParallelExecutionManager = new ParallelProxyExecutionManager(proxyManagerFunc, 2); var mockHandler = new Mock(); @@ -514,7 +525,7 @@ public void StartTestRunShouldAggregateRunData() Task.Run(() => { - proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); + this.proxyParallelExecutionManager.StartTestRun(testRunCriteria, mockHandler.Object); }); eventHandle.WaitOne();