Skip to content

Commit

Permalink
Fix panic in acceptance tests (#3592)
Browse files Browse the repository at this point in the history
* Fix panic in acceptance tests

This commit attempts to address a panic that occurs in acceptance
tests if a server in the cluster fails to start.

Signed-off-by: George Robinson <george.robinson@grafana.com>

* Remove started and check am.cmd.Process != nil

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
  • Loading branch information
grobinson-grafana authored Feb 13, 2024
1 parent 604d442 commit 4d6ddd2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions test/with_api_v2/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,15 @@ func (t *AcceptanceTest) Run() {

for _, am := range t.amc.ams {
am.errc = errc
defer func(am *Alertmanager) {
am.Terminate()
am.cleanup()
t.Logf("stdout:\n%v", am.cmd.Stdout)
t.Logf("stderr:\n%v", am.cmd.Stderr)
}(am)
t.T.Cleanup(am.Terminate)
t.T.Cleanup(am.cleanup)
}

err := t.amc.Start()
if err != nil {
t.T.Fatal(err)
t.T.Log(err)
t.T.Fail()
return
}

// Set the reference time right before running the test actions to avoid
Expand Down Expand Up @@ -251,10 +249,10 @@ type Alertmanager struct {
apiAddr string
clusterAddr string
clientV2 *apiclient.AlertmanagerAPI
cmd *exec.Cmd
confFile *os.File
dir string

cmd *exec.Cmd
errc chan<- error
}

Expand Down Expand Up @@ -386,8 +384,12 @@ func (amc *AlertmanagerCluster) Terminate() {
// data.
func (am *Alertmanager) Terminate() {
am.t.Helper()
if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGTERM); err != nil {
am.t.Logf("Error sending SIGTERM to Alertmanager process: %v", err)
if am.cmd.Process != nil {
if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGTERM); err != nil {
am.t.Logf("Error sending SIGTERM to Alertmanager process: %v", err)
}
am.t.Logf("stdout:\n%v", am.cmd.Stdout)
am.t.Logf("stderr:\n%v", am.cmd.Stderr)
}
}

Expand All @@ -401,8 +403,10 @@ func (amc *AlertmanagerCluster) Reload() {
// Reload sends the reloading signal to the Alertmanager process.
func (am *Alertmanager) Reload() {
am.t.Helper()
if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGHUP); err != nil {
am.t.Fatalf("Error sending SIGHUP to Alertmanager process: %v", err)
if am.cmd.Process != nil {
if err := syscall.Kill(am.cmd.Process.Pid, syscall.SIGHUP); err != nil {
am.t.Fatalf("Error sending SIGHUP to Alertmanager process: %v", err)
}
}
}

Expand Down

0 comments on commit 4d6ddd2

Please sign in to comment.