From bca85bc31cda2dd73777b4a4c7be9b8f97af9e99 Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Thu, 24 Oct 2024 18:14:57 +0200 Subject: [PATCH] internal/civisibility: auto test retries max retries fix (#2947) --- .../integrations/gotesting/instrumentation.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/civisibility/integrations/gotesting/instrumentation.go b/internal/civisibility/integrations/gotesting/instrumentation.go index f8a0c3502f..bd35f429c9 100644 --- a/internal/civisibility/integrations/gotesting/instrumentation.go +++ b/internal/civisibility/integrations/gotesting/instrumentation.go @@ -190,11 +190,14 @@ func applyFlakyTestRetriesAdditionalFeature(targetFunc func(*testing.T)) func(*t initialRetryCount: flakyRetrySettings.RetryCount, adjustRetryCount: nil, // No adjustRetryCount shouldRetry: func(ptrToLocalT *testing.T, executionIndex int, remainingRetries int64) bool { - remainingTotalRetries := atomic.AddInt64(&flakyRetrySettings.RemainingTotalRetryCount, -1) // Decide whether to retry - return ptrToLocalT.Failed() && remainingRetries >= 0 && remainingTotalRetries >= 0 + return ptrToLocalT.Failed() && remainingRetries >= 0 && atomic.LoadInt64(&flakyRetrySettings.RemainingTotalRetryCount) >= 0 + }, + perExecution: func(ptrToLocalT *testing.T, executionIndex int, duration time.Duration) { + if executionIndex > 0 { + atomic.AddInt64(&flakyRetrySettings.RemainingTotalRetryCount, -1) + } }, - perExecution: nil, // No perExecution needed onRetryEnd: func(t *testing.T, executionIndex int, lastPtrToLocalT *testing.T) { // Update original `t` with results from last execution tCommonPrivates := getTestPrivateFields(t) @@ -223,11 +226,11 @@ func applyFlakyTestRetriesAdditionalFeature(targetFunc func(*testing.T)) func(*t } fmt.Printf(" [ %v after %v retries by Datadog's auto test retries ]\n", status, executionIndex) - } - // Check if total retry count was exceeded - if flakyRetrySettings.RemainingTotalRetryCount < 1 { - fmt.Println(" the maximum number of total retries was exceeded.") + // Check if total retry count was exceeded + if atomic.LoadInt64(&flakyRetrySettings.RemainingTotalRetryCount) < 1 { + fmt.Println(" the maximum number of total retries was exceeded.") + } } }, execMetaAdjust: nil, // No execMetaAdjust needed