From 0073647981898fc54ef1abb2ad429a58f18544f4 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 12 Oct 2015 07:35:22 +0200 Subject: [PATCH] Restructure acceptance test files --- test/acceptance/retry_test.go | 69 ----------------- .../{simple_test.go => send_test.go} | 54 +++++++------- test/acceptance/silence_test.go | 74 +++++++++++++++++++ 3 files changed, 101 insertions(+), 96 deletions(-) delete mode 100644 test/acceptance/retry_test.go rename test/acceptance/{simple_test.go => send_test.go} (77%) create mode 100644 test/acceptance/silence_test.go diff --git a/test/acceptance/retry_test.go b/test/acceptance/retry_test.go deleted file mode 100644 index bc8f9b97..00000000 --- a/test/acceptance/retry_test.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 Prometheus Team -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test - -import ( - "fmt" - "testing" - "time" - - . "github.com/prometheus/alertmanager/test" -) - -func TestRetry(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 := ` -routes: -- send_to: "default" - group_wait: 1s - group_interval: 1s - repeat_interval: 3s - -notification_configs: -- name: "default" - webhook_configs: - - url: 'http://%s' - - url: 'http://%s' -` - - at := NewAcceptanceTest(t, &AcceptanceOpts{ - Tolerance: 150 * time.Millisecond, - }) - - co1 := at.Collector("webhook") - wh1 := NewWebhook(co1) - - co2 := at.Collector("webhook_failing") - wh2 := NewWebhook(co2) - - wh2.Func = func(ts float64) bool { - // Fail the first two interval periods but eventually - // succeed in the third interval after a few failed attempts. - return ts < 4.5 - } - - am := at.Alertmanager(fmt.Sprintf(conf, wh1.Address(), wh2.Address())) - - am.Push(At(1), Alert("alertname", "test1")) - - co1.Want(Between(2, 2.5), Alert("alertname", "test1").Active(1)) - co1.Want(Between(5, 5.5), Alert("alertname", "test1").Active(1)) - - co2.Want(Between(4.5, 5), Alert("alertname", "test1").Active(1)) -} diff --git a/test/acceptance/simple_test.go b/test/acceptance/send_test.go similarity index 77% rename from test/acceptance/simple_test.go rename to test/acceptance/send_test.go index 72b86949..22d569fb 100644 --- a/test/acceptance/simple_test.go +++ b/test/acceptance/send_test.go @@ -21,7 +21,12 @@ import ( . "github.com/prometheus/alertmanager/test" ) -func TestSomething(t *testing.T) { +// This file contains acceptance tests around the basic sending logic +// for notifications, which includes batching and ensuring that each +// notification is eventually sent at least once and ideally exactly +// once. + +func TestRepeat(t *testing.T) { t.Parallel() conf := ` @@ -74,56 +79,51 @@ notification_configs: at.Run() } -func TestSilencing(t *testing.T) { +func TestRetry(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 := ` routes: - send_to: "default" group_wait: 1s group_interval: 1s - repeat_interval: 1s + repeat_interval: 3s notification_configs: - name: "default" webhook_configs: - url: 'http://%s' + - url: 'http://%s' ` at := NewAcceptanceTest(t, &AcceptanceOpts{ Tolerance: 150 * time.Millisecond, }) - co := at.Collector("webhook") - wh := NewWebhook(co) + co1 := at.Collector("webhook") + wh1 := NewWebhook(co1) - am := at.Alertmanager(fmt.Sprintf(conf, wh.Address())) + co2 := at.Collector("webhook_failing") + wh2 := NewWebhook(co2) - // No repeat interval is configured. Thus, we receive an alert - // notification every second. - am.Push(At(1), Alert("alertname", "test1").Active(1)) - am.Push(At(1), Alert("alertname", "test2").Active(1)) + wh2.Func = func(ts float64) bool { + // Fail the first two interval periods but eventually + // succeed in the third interval after a few failed attempts. + return ts < 4.5 + } - co.Want(Between(2, 2.5), - Alert("alertname", "test1").Active(1), - Alert("alertname", "test2").Active(1), - ) + am := at.Alertmanager(fmt.Sprintf(conf, wh1.Address(), wh2.Address())) - // Add a silence that affects the first alert. - am.SetSilence(At(2.5), Silence(2, 4.5).Match("alertname", "test1")) + am.Push(At(1), Alert("alertname", "test1")) - co.Want(Between(3, 3.5), Alert("alertname", "test2").Active(1)) - co.Want(Between(4, 4.5), Alert("alertname", "test2").Active(1)) + co1.Want(Between(2, 2.5), Alert("alertname", "test1").Active(1)) + co1.Want(Between(5, 5.5), Alert("alertname", "test1").Active(1)) - // Silence should be over now and we receive both alerts again. - - co.Want(Between(5, 5.5), - Alert("alertname", "test1").Active(1), - Alert("alertname", "test2").Active(1), - ) - - // Start the flow as defined above and run the checks afterwards. - at.Run() + co2.Want(Between(4.5, 5), Alert("alertname", "test1").Active(1)) } func TestBatching(t *testing.T) { diff --git a/test/acceptance/silence_test.go b/test/acceptance/silence_test.go new file mode 100644 index 00000000..7440f30f --- /dev/null +++ b/test/acceptance/silence_test.go @@ -0,0 +1,74 @@ +// Copyright 2015 Prometheus Team +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package test + +import ( + "fmt" + "testing" + "time" + + . "github.com/prometheus/alertmanager/test" +) + +func TestSilencing(t *testing.T) { + t.Parallel() + + conf := ` +routes: +- send_to: "default" + group_wait: 1s + group_interval: 1s + repeat_interval: 1s + +notification_configs: +- 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())) + + // No repeat interval is configured. Thus, we receive an alert + // notification every second. + am.Push(At(1), Alert("alertname", "test1").Active(1)) + am.Push(At(1), Alert("alertname", "test2").Active(1)) + + co.Want(Between(2, 2.5), + Alert("alertname", "test1").Active(1), + Alert("alertname", "test2").Active(1), + ) + + // Add a silence that affects the first alert. + am.SetSilence(At(2.5), Silence(2, 4.5).Match("alertname", "test1")) + + co.Want(Between(3, 3.5), Alert("alertname", "test2").Active(1)) + co.Want(Between(4, 4.5), Alert("alertname", "test2").Active(1)) + + // Silence should be over now and we receive both alerts again. + + co.Want(Between(5, 5.5), + Alert("alertname", "test1").Active(1), + Alert("alertname", "test2").Active(1), + ) + + // Start the flow as defined above and run the checks afterwards. + at.Run() +}