From 1fc0a345398615909688e3a241fc0d16443146d5 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Mon, 8 Apr 2024 12:09:42 +0200 Subject: [PATCH] chore: fix assertAlertmanagersAreResilientToDisruption() (#454) 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 --- test/e2e/monitoring_stack_controller_test.go | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/e2e/monitoring_stack_controller_test.go b/test/e2e/monitoring_stack_controller_test.go index 6857666e..0645c55c 100644 --- a/test/e2e/monitoring_stack_controller_test.go +++ b/test/e2e/monitoring_stack_controller_test.go @@ -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) } } }