diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/PerRequestServerDataConsumerService.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/PerRequestServerDataConsumerService.cs index fe89730a84..b0b884797e 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/PerRequestServerDataConsumerService.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/PerRequestServerDataConsumerService.cs @@ -243,6 +243,11 @@ private void AddOrUpdateTestNodeStateStatistics(TestNodeUid testNodeUid, bool ha return; } + if (existingStatistics.HasPassed == hasPassed) + { + return; + } + if (hasPassed) { existingStatistics.TotalPassedRetries++; diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs index 8fe8ab2684..46ac014e89 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs @@ -133,12 +133,12 @@ public void PopulateTestNodeStatistics_WithDuplicatePassedEvents() Assert.AreEqual(0, statistics.TotalDiscoveredTests); Assert.AreEqual(1, statistics.TotalPassedTests); Assert.AreEqual(0, statistics.TotalFailedTests); - Assert.AreEqual(1, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalPassedRetries); Assert.AreEqual(0, statistics.TotalFailedRetries); } [TestMethod] - public void PopulateTestNodeStatistics_WithEventsForSameUid() + public void PopulateTestNodeStatistics_WithOutcomeChangeForSameUid_CountsAsRetry() { PropertyBag properties = new( new FailedTestNodeStateProperty("failed")); @@ -148,7 +148,7 @@ public void PopulateTestNodeStatistics_WithEventsForSameUid() PropertyBag otherProperties = new( PassedTestNodeStateProperty.CachedInstance); - TestNodeUpdateMessage otherTestNode = new(new SessionUid(string.Empty), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty, Properties = otherProperties }); + TestNodeUpdateMessage otherTestNode = new(new SessionUid("2"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty, Properties = otherProperties }); _service.PopulateTestNodeStatistics(testNode); _service.PopulateTestNodeStatistics(otherTestNode); @@ -161,6 +161,50 @@ public void PopulateTestNodeStatistics_WithEventsForSameUid() Assert.AreEqual(0, statistics.TotalFailedRetries); } + [TestMethod] + public void PopulateTestNodeStatistics_WithDuplicateFailedEvents_DoesNotCountAsRetry() + { + PropertyBag properties = new( + new FailedTestNodeStateProperty("failed")); + + TestNodeUpdateMessage testNode = new(new SessionUid("1"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty, Properties = properties }); + + _service.PopulateTestNodeStatistics(testNode); + _service.PopulateTestNodeStatistics(testNode); + + TestNodeStatistics statistics = _service.GetTestNodeStatistics(); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(0, statistics.TotalPassedTests); + Assert.AreEqual(1, statistics.TotalFailedTests); + Assert.AreEqual(0, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalFailedRetries); + } + + [TestMethod] + public void PopulateTestNodeStatistics_WithDuplicateEventAfterOutcomeChange_OnlyCountsFirstRetry() + { + PropertyBag failedProperties = new( + new FailedTestNodeStateProperty("failed")); + + TestNodeUpdateMessage failedTestNode = new(new SessionUid("1"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty, Properties = failedProperties }); + + PropertyBag passedProperties = new( + PassedTestNodeStateProperty.CachedInstance); + + TestNodeUpdateMessage passedTestNode = new(new SessionUid("1"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty, Properties = passedProperties }); + + _service.PopulateTestNodeStatistics(failedTestNode); + _service.PopulateTestNodeStatistics(passedTestNode); + _service.PopulateTestNodeStatistics(passedTestNode); + + TestNodeStatistics statistics = _service.GetTestNodeStatistics(); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(1, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); + Assert.AreEqual(1, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalFailedRetries); + } + [TestMethod] public void PopulateTestNodeStatistics_WithEventsForDifferentUids() {