From cbc94fad4695069488bae67aa024f5bc89854434 Mon Sep 17 00:00:00 2001 From: gotjosh Date: Thu, 7 Jul 2022 11:07:13 +0100 Subject: [PATCH] Acceptance Tests: Better error messages The CI keeps reporting flakes for our acceptance test around the starting and stopping of the Alertmanagers. While I have an idea of where these failures are coming from, it would be nice to get a confirmation by structuring our error messages a bit better. Signed-off-by: gotjosh --- test/with_api_v2/acceptance.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/with_api_v2/acceptance.go b/test/with_api_v2/acceptance.go index 0a3ed838..3c3d22ae 100644 --- a/test/with_api_v2/acceptance.go +++ b/test/with_api_v2/acceptance.go @@ -274,14 +274,14 @@ func (amc *AlertmanagerCluster) Start() error { for _, am := range amc.ams { err := am.Start(peerFlags) if err != nil { - return fmt.Errorf("starting alertmanager cluster: %v", err.Error()) + return fmt.Errorf("failed to start alertmanager cluster: %v", err.Error()) } } for _, am := range amc.ams { err := am.WaitForCluster(len(amc.ams)) if err != nil { - return fmt.Errorf("starting alertmanager cluster: %v", err.Error()) + return fmt.Errorf("failed to wait for Alertmanager instance %q to join cluster: %v", am.clusterAddr, err.Error()) } } @@ -322,7 +322,7 @@ func (am *Alertmanager) Start(additionalArg []string) error { am.cmd = cmd if err := am.cmd.Start(); err != nil { - return fmt.Errorf("starting alertmanager failed: %s", err) + return err } go func() { @@ -332,14 +332,15 @@ func (am *Alertmanager) Start(additionalArg []string) error { }() time.Sleep(50 * time.Millisecond) + var lastErr error for i := 0; i < 10; i++ { - _, err := am.clientV2.General.GetStatus(nil) - if err == nil { + _, lastErr = am.clientV2.General.GetStatus(nil) + if lastErr == nil { return nil } time.Sleep(500 * time.Millisecond) } - return fmt.Errorf("starting alertmanager failed: timeout") + return fmt.Errorf("unable to get a successful response from the Alertmanager: %v", lastErr) } // WaitForCluster waits for the Alertmanager instance to join a cluster with the @@ -364,8 +365,7 @@ func (am *Alertmanager) WaitForCluster(size int) error { } return fmt.Errorf( - "failed to wait for Alertmanager instance %q to join cluster: expected %v peers, but got %v", - am.clusterAddr, + "expected %v peers, but got %v", size, len(status.Payload.Cluster.Peers), ) @@ -384,7 +384,7 @@ func (amc *AlertmanagerCluster) Terminate() { func (am *Alertmanager) Terminate() { am.t.Helper() if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGTERM); err != nil { - am.t.Fatalf("Error sending SIGTERM to Alertmanager process: %v", err) + am.t.Logf("Error sending SIGTERM to Alertmanager process: %v", err) } }