Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/cli/acceptance/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ receivers:
Tolerance: 1 * time.Second,
})
co := at.Collector("webhook")
wh := NewWebhook(co)
wh := NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
require.NoError(t, amc.Start())
Expand Down Expand Up @@ -475,7 +475,7 @@ receivers:
Tolerance: 1 * time.Second,
})
co := at.Collector("webhook")
wh := NewWebhook(co)
wh := NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
require.NoError(t, amc.Start())
Expand Down
2 changes: 1 addition & 1 deletion test/testutils/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (amc *AlertmanagerCluster) Terminate() {
// data.
func (am *Alertmanager) Terminate() {
am.T.Helper()
if am.cmd.Process != nil {
if am.cmd != nil && 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)
}
Expand Down
8 changes: 8 additions & 0 deletions test/testutils/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package testutils
import (
"encoding/json"
"fmt"
"io"
"maps"
"net/http"
"net/http/httptest"
"reflect"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -182,6 +184,7 @@ type MockWebhook struct {
opts *AcceptanceOpts
collector *Collector
addr string
closing atomic.Bool

// Func is called early on when retrieving a notification by an
// Alertmanager. If Func returns true, the given notification is dropped.
Expand All @@ -202,6 +205,7 @@ func NewWebhook(t *testing.T, c *Collector) *MockWebhook {
wh.addr = server.Listener.Addr().String()

t.Cleanup(func() {
wh.closing.Store(true)
server.Close()
})

Expand All @@ -222,6 +226,10 @@ func (ws *MockWebhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {

var v webhook.Message
if err := dec.Decode(&v); err != nil {
// During shutdown, ignore EOF errors from interrupted connections
if ws.closing.Load() && (err == io.EOF || err.Error() == "EOF") {
return
}
panic(err)
}

Expand Down
Loading