diff --git a/src/Agent.Worker/TestResults/Legacy/LegacyTestRunDataPublisher.cs b/src/Agent.Worker/TestResults/Legacy/LegacyTestRunDataPublisher.cs index 63f17d87f0..a71775305e 100644 --- a/src/Agent.Worker/TestResults/Legacy/LegacyTestRunDataPublisher.cs +++ b/src/Agent.Worker/TestResults/Legacy/LegacyTestRunDataPublisher.cs @@ -36,6 +36,7 @@ public class LegacyTestRunDataPublisher : AgentService, ILegacyTestRunDataPublis private int _runCounter = 0; private IFeatureFlagService _featureFlagService; private bool _calculateTestRunSummary; + private bool _isFlakyCheckEnabled; private string _testRunner; private ITestResultsServer _testResultsServer; private TestRunDataPublisherHelper _testRunPublisherHelper; @@ -54,6 +55,7 @@ public void InitializePublisher(IExecutionContext context, string projectName, V _testResultsServer = HostContext.GetService(); _testResultsServer.InitializeServer(connection, _executionContext); _calculateTestRunSummary = _featureFlagService.GetFeatureFlagState(TestResultsConstants.CalculateTestRunSummaryFeatureFlag, TestResultsConstants.TFSServiceInstanceGuid); + _isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); _testRunPublisherHelper = new TestRunDataPublisherHelper(_executionContext, null, _testRunPublisher, _testResultsServer); Trace.Leaving(); } @@ -208,9 +210,7 @@ private async Task PublishAllTestResultsToSingleTestRunAsync(List // Check failed results for flaky aware // Fallback to flaky aware if there are any failures. - bool isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); - - if (isTestRunOutcomeFailed && isFlakyCheckEnabled) + if (isTestRunOutcomeFailed && _isFlakyCheckEnabled) { IList publishedRuns = new List(); publishedRuns.Add(updatedRun); @@ -313,9 +313,7 @@ private async Task PublishToNewTestRunPerTestResultFileAsync(List // Check failed results for flaky aware // Fallback to flaky aware if there are any failures. - bool isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); - - if (isTestRunOutcomeFailed && isFlakyCheckEnabled) + if (isTestRunOutcomeFailed && _isFlakyCheckEnabled) { var runOutcome = _testRunPublisherHelper.CheckRunsForFlaky(publishedRuns, _projectName); if (runOutcome != null && runOutcome.HasValue) diff --git a/src/Agent.Worker/TestResults/TestDataPublisher.cs b/src/Agent.Worker/TestResults/TestDataPublisher.cs index af99350378..df83652f00 100644 --- a/src/Agent.Worker/TestResults/TestDataPublisher.cs +++ b/src/Agent.Worker/TestResults/TestDataPublisher.cs @@ -41,6 +41,7 @@ public sealed class TestDataPublisher : AgentService, ITestDataPublisher private IFeatureFlagService _featureFlagService; private string _testRunner; private bool _calculateTestRunSummary; + private bool _isFlakyCheckEnabled; private TestRunDataPublisherHelper _testRunPublisherHelper; private ITestResultsServer _testResultsServer; @@ -58,6 +59,8 @@ public void InitializePublisher(IExecutionContext context, string projectName, V var extensionManager = HostContext.GetService(); _featureFlagService = HostContext.GetService(); _featureFlagService.InitializeFeatureService(_executionContext, connection); + _calculateTestRunSummary = _featureFlagService.GetFeatureFlagState(TestResultsConstants.CalculateTestRunSummaryFeatureFlag, TestResultsConstants.TFSServiceInstanceGuid); + _isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); ; _parser = (extensionManager.GetExtensions()).FirstOrDefault(x => _testRunner.Equals(x.Name, StringComparison.OrdinalIgnoreCase)); _testRunPublisherHelper = new TestRunDataPublisherHelper(_executionContext, _testRunPublisher, null, _testResultsServer); Trace.Leaving(); @@ -86,8 +89,6 @@ public void InitializePublisher(IExecutionContext context, string projectName, V IList publishedRuns = publishtestRunDataTask.Result; - _calculateTestRunSummary = _featureFlagService.GetFeatureFlagState(TestResultsConstants.CalculateTestRunSummaryFeatureFlag, TestResultsConstants.TFSServiceInstanceGuid); - var isTestRunOutcomeFailed = GetTestRunOutcome(_executionContext, testRunData, out TestRunSummary testRunSummary); // Storing testrun summary in environment variable, which will be read by PublishPipelineMetadataTask and publish to evidence store. @@ -98,9 +99,7 @@ public void InitializePublisher(IExecutionContext context, string projectName, V // Check failed results for flaky aware // Fallback to flaky aware if there are any failures. - bool isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); - - if (isTestRunOutcomeFailed && isFlakyCheckEnabled) + if (isTestRunOutcomeFailed && _isFlakyCheckEnabled) { var runOutcome = _testRunPublisherHelper.CheckRunsForFlaky(publishedRuns, _projectName); if (runOutcome != null && runOutcome.HasValue) @@ -188,8 +187,6 @@ public void InitializePublisher(IExecutionContext context, string projectName, V IList publishedRuns = publishtestRunDataTask.Result; - _calculateTestRunSummary = _featureFlagService.GetFeatureFlagState(TestResultsConstants.CalculateTestRunSummaryFeatureFlag, TestResultsConstants.TFSServiceInstanceGuid); - var isTestRunOutcomeFailed = GetTestRunOutcome(_executionContext, testRunData, out TestRunSummary testRunSummary); // Storing testrun summary in environment variable, which will be read by PublishPipelineMetadataTask and publish to evidence store. @@ -200,9 +197,7 @@ public void InitializePublisher(IExecutionContext context, string projectName, V // Check failed results for flaky aware // Fallback to flaky aware if there are any failures. - bool isFlakyCheckEnabled = _featureFlagService.GetFeatureFlagState(TestResultsConstants.EnableFlakyCheckInAgentFeatureFlag, TestResultsConstants.TCMServiceInstanceGuid); - - if (isTestRunOutcomeFailed && isFlakyCheckEnabled) + if (isTestRunOutcomeFailed && _isFlakyCheckEnabled) { var runOutcome = _testRunPublisherHelper.CheckRunsForFlaky(publishedRuns, _projectName); if (runOutcome != null && runOutcome.HasValue)