Skip to content

Commit 7347d6e

Browse files
aareetclaude
andauthored
[CRE-3579] fix: flaky Test_StratReconciliation_RetriesWithBackoff (#22082)
fix: flaky Test_StratReconciliation_RetriesWithBackoff Fix data race on retryCount (plain int accessed across goroutines without synchronization) by using atomic.Int32. Also fix the test to actually verify retry behavior: wait for the full retry cycle (2 failures + 1 success) instead of exiting after the first failed attempt. Use a faster ticker and shorter retry interval to avoid unnecessary slowness. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6c93c02 commit 7347d6e

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

core/services/workflows/syncer/workflow_syncer_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
rand2 "math/rand/v2"
1313
"strings"
1414
"sync"
15+
"sync/atomic"
1516
"testing"
1617
"time"
1718

@@ -838,10 +839,9 @@ func Test_StratReconciliation_RetriesWithBackoff(t *testing.T) {
838839
workflow.ID = workflowID
839840
registerWorkflow(t, backendTH, wfRegistryC, workflow)
840841

841-
var retryCount int
842+
var retryCount atomic.Int32
842843
testEventHandler := newTestEvtHandler(func() error {
843-
if retryCount <= 1 {
844-
retryCount++
844+
if retryCount.Add(1) <= 2 {
845845
return errors.New("error handling event")
846846
}
847847
return nil
@@ -866,20 +866,24 @@ func Test_StratReconciliation_RetriesWithBackoff(t *testing.T) {
866866
err: nil,
867867
},
868868
NewEngineRegistry(),
869-
WithRetryInterval(1*time.Second),
869+
WithTicker(time.NewTicker(1*time.Second).C),
870+
WithRetryInterval(100*time.Millisecond),
870871
)
871872
require.NoError(t, err)
872873

873874
servicetest.Run(t, worker)
874875

876+
// Wait for the handler to be called 3 times: 2 failures with backoff + 1 success
875877
require.Eventually(t, func() bool {
876-
return len(testEventHandler.GetEvents()) == 1
878+
return retryCount.Load() >= 3
877879
}, 30*time.Second, 1*time.Second)
878880

879-
event := testEventHandler.GetEvents()[0]
880-
assert.Equal(t, WorkflowRegisteredEvent, event.EventType)
881-
882-
assert.Equal(t, 1, retryCount)
881+
// All 3 calls (2 failures + 1 success) should have appended events
882+
events := testEventHandler.GetEvents()
883+
require.GreaterOrEqual(t, len(events), 3)
884+
for _, event := range events {
885+
assert.Equal(t, WorkflowRegisteredEvent, event.EventType)
886+
}
883887
}
884888

885889
func updateAuthorizedAddress(

0 commit comments

Comments
 (0)