Skip to content

Commit

Permalink
test: add reload test
Browse files Browse the repository at this point in the history
This test reloads the Alertmanager to verify, that it properly keeps
state and sends notifications correctly across reloads.
  • Loading branch information
fabxc committed Apr 18, 2017
1 parent af8cfdd commit ff5ecff
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/acceptance/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,48 @@ receivers:

at.Run()
}

func TestReload(t *testing.T) {
t.Parallel()

// We create a notification config that fans out into two different
// webhooks.
// The succeeding one must still only receive the first successful
// notifications. Sending to the succeeding one must eventually succeed.
conf := `
route:
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 6s
repeat_interval: 10m
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
`

at := NewAcceptanceTest(t, &AcceptanceOpts{
Tolerance: 150 * time.Millisecond,
})

co := at.Collector("webhook")
wh := NewWebhook(co)

am := at.Alertmanager(fmt.Sprintf(conf, wh.Address()))

am.Push(At(1), Alert("alertname", "test1"))
at.Do(At(3), am.Reload)
am.Push(At(4), Alert("alertname", "test2"))

co.Want(Between(2, 2.5), Alert("alertname", "test1").Active(1))
// Timers are reset on reload regardless, so we count the 6 second group
// interval from 3 onwards.
co.Want(Between(9, 9.5),
Alert("alertname", "test1").Active(1),
Alert("alertname", "test2").Active(4),
)

at.Run()
}
1 change: 1 addition & 0 deletions test/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func NewWebhook(c *Collector) *MockWebhook {
wh := &MockWebhook{
listener: l,
collector: c,
opts: c.opts,
}
go http.Serve(l, wh)

Expand Down

0 comments on commit ff5ecff

Please sign in to comment.