Skip to content

Commit bc0ee0d

Browse files
flavianmissiopenshift-cherrypick-robot
authored andcommitted
leaderelection_test: assert on pods that have acquired leader lease
in some cases, this test would flake when one of the pods was waiting for the leader lease but its last log message was 'error initially creating leader election record' instead of the expected 'attempting to acquire leader lease'. this commit changes the test to instead look for pods that successfully acquired the lease.
1 parent e41516d commit bc0ee0d

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

test/e2e/leaderelection_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package e2e_test
22

33
import (
44
"context"
5-
"strings"
5+
"regexp"
66
"testing"
77
"time"
88

@@ -50,22 +50,17 @@ func TestLeaderElection(t *testing.T) {
5050
t.Fatalf("error reading operator logs: %v", err)
5151
}
5252

53-
awaitingPods := int32(0)
53+
re := regexp.MustCompile(".*successfully acquired lease.*")
54+
acquiredLease := 0
5455
for _, podLogs := range allLogs {
5556
for _, containerLogs := range podLogs {
56-
lastLine := len(containerLogs) - 1
57-
if lastLine < 0 {
58-
continue
59-
}
60-
61-
if strings.Contains(containerLogs[lastLine], "attempting to acquire leader lease") {
62-
awaitingPods++
57+
if containerLogs.Contains(re) {
58+
acquiredLease++
6359
}
6460
}
6561
}
6662

67-
numberOfAwaitingPods := numberOfReplicas - 1
68-
if awaitingPods != numberOfAwaitingPods {
69-
t.Errorf("multiple operators running at the same time")
63+
if acquiredLease > 1 {
64+
t.Errorf("multiple operators running at the same time, %d pods acquired lease, expected 1.", acquiredLease)
7065
}
7166
}

0 commit comments

Comments
 (0)