Skip to content

Commit 62d2e1b

Browse files
authored
test: reduce flakiness of TestSurfaceFightError (#1808)
To trigger the fight detector, the remediator needs to update the same object at least 5 times in a minute. If multiple watch events happen in too quick of succession, the updates might get batched together as a single remediation. Continuing to emit update events until the remediator detects the fight should make this test less flaky.
1 parent 84597c9 commit 62d2e1b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

e2e/testcases/remediator_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package e2e
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"testing"
2021
"time"
@@ -45,17 +46,28 @@ func TestSurfaceFightError(t *testing.T) {
4546
nt.Must(nt.WatchForAllSyncs())
4647

4748
// Make the # of updates exceed the fightThreshold defined in pkg/syncer/reconcile/fight_detector.go
49+
ctx, cancel := context.WithCancel(t.Context())
4850
go func() {
49-
for i := 0; i <= 5; i++ {
50-
nt.MustMergePatch(ns, `{"metadata": {"annotations": {"foo": "baz"}}}`)
51-
nt.MustMergePatch(rb, `{"metadata": {"annotations": {"foo": "baz"}}}`)
52-
time.Sleep(time.Second)
51+
for {
52+
select {
53+
case <-ctx.Done():
54+
nt.T.Log("Stopping async status updates")
55+
return
56+
default:
57+
nt.T.Log("async status update")
58+
nt.MustMergePatch(ns, `{"metadata": {"annotations": {"foo": "baz"}}}`)
59+
time.Sleep(time.Second)
60+
}
5361
}
5462
}()
5563

5664
nt.T.Log("The RootSync reports a fight error")
57-
nt.Must(nt.Watcher.WatchForRootSyncSyncError(configsync.RootSyncName, status.FightErrorCode,
58-
"This may indicate Config Sync is fighting with another controller over the object.", nil))
65+
err := nt.Watcher.WatchForRootSyncSyncError(configsync.RootSyncName, status.FightErrorCode,
66+
"This may indicate Config Sync is fighting with another controller over the object.", nil)
67+
cancel()
68+
if err != nil {
69+
nt.T.Fatal(err)
70+
}
5971

6072
rootSyncNN := nomostest.RootSyncNN(configsync.RootSyncName)
6173
rootSyncLabels, err := nomostest.MetricLabelsForRootSync(nt, rootSyncNN)

0 commit comments

Comments
 (0)