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 <josue.abreu@gmail.com>
This commit is contained in:
gotjosh 2022-07-07 11:07:13 +01:00
parent 17af1d69d2
commit cbc94fad46
No known key found for this signature in database
GPG Key ID: A6E1DDE38FF3C74E
1 changed files with 9 additions and 9 deletions

View File

@ -274,14 +274,14 @@ func (amc *AlertmanagerCluster) Start() error {
for _, am := range amc.ams { for _, am := range amc.ams {
err := am.Start(peerFlags) err := am.Start(peerFlags)
if err != nil { 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 { for _, am := range amc.ams {
err := am.WaitForCluster(len(amc.ams)) err := am.WaitForCluster(len(amc.ams))
if err != nil { 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 am.cmd = cmd
if err := am.cmd.Start(); err != nil { if err := am.cmd.Start(); err != nil {
return fmt.Errorf("starting alertmanager failed: %s", err) return err
} }
go func() { go func() {
@ -332,14 +332,15 @@ func (am *Alertmanager) Start(additionalArg []string) error {
}() }()
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
var lastErr error
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
_, err := am.clientV2.General.GetStatus(nil) _, lastErr = am.clientV2.General.GetStatus(nil)
if err == nil { if lastErr == nil {
return nil return nil
} }
time.Sleep(500 * time.Millisecond) 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 // 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( return fmt.Errorf(
"failed to wait for Alertmanager instance %q to join cluster: expected %v peers, but got %v", "expected %v peers, but got %v",
am.clusterAddr,
size, size,
len(status.Payload.Cluster.Peers), len(status.Payload.Cluster.Peers),
) )
@ -384,7 +384,7 @@ func (amc *AlertmanagerCluster) Terminate() {
func (am *Alertmanager) Terminate() { func (am *Alertmanager) Terminate() {
am.t.Helper() am.t.Helper()
if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGTERM); err != nil { 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)
} }
} }