Skip to content

Commit

Permalink
chore: fix assertAlertmanagersAreResilientToDisruption() (#454)
Browse files Browse the repository at this point in the history
I suspect that the test was flaky because it uses the address of the
loop variable (see https://go.dev/blog/loopvar-preview).

Signed-off-by: Simon Pasquier <[email protected]>
  • Loading branch information
simonpasquier authored Apr 8, 2024
1 parent 4bd2e62 commit 1fc0a34
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/e2e/monitoring_stack_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,22 @@ func assertAlertmanagersAreOnDifferentNodes(t *testing.T, pods []corev1.Pod) {
}

func assertAlertmanagersAreResilientToDisruption(t *testing.T, pods []corev1.Pod) {
for i, pod := range pods {
lastPod := i == len(pods)-1
err := f.Evict(&pod, 0)
if lastPod && err == nil {
t.Fatal("expected an error when evicting the last pod, got nil")
errs := make([]error, len(pods))
for i := range pods {
pod := pods[i]
errs[i] = f.Evict(&pod, 0)
}

for i, err := range errs {
if i != len(errs)-1 {
if err != nil {
t.Fatalf("expected no error when evicting pod with index %d, got %v", i, err)
}
continue
}
if !lastPod && err != nil {
t.Fatalf("expected no error when evicting pod with index %d, got %v", i, err)

if err == nil {
t.Fatalf("expected an error when evicting the last pod %d, got nil", i)
}
}
}
Expand Down

0 comments on commit 1fc0a34

Please sign in to comment.