Fix broken tests

This commit is contained in:
Goutham Veeramachaneni 2017-03-03 03:16:30 +05:30
parent f35816613e
commit af222b63fc
No known key found for this signature in database
GPG key ID: F1C217E8E9023CAD

View file

@ -64,6 +64,7 @@ func TestPostPath(t *testing.T) {
func TestHandlerNextBatch(t *testing.T) { func TestHandlerNextBatch(t *testing.T) {
h := New(&Options{}, prometheus.DefaultRegisterer) h := New(&Options{}, prometheus.DefaultRegisterer)
defer unregisterMetrics()
for i := range make([]struct{}, 2*maxBatchSize+1) { for i := range make([]struct{}, 2*maxBatchSize+1) {
h.queue = append(h.queue, &model.Alert{ h.queue = append(h.queue, &model.Alert{
@ -119,6 +120,14 @@ func alertsEqual(a, b model.Alerts) bool {
return true return true
} }
func unregisterMetrics() {
m := newAlertMetrics(nil, &Options{})
prometheus.DefaultRegisterer.Unregister(m.latency)
prometheus.DefaultRegisterer.Unregister(m.errors)
prometheus.DefaultRegisterer.Unregister(m.sent)
prometheus.DefaultRegisterer.Unregister(m.dropped)
}
func TestHandlerSendAll(t *testing.T) { func TestHandlerSendAll(t *testing.T) {
var ( var (
expected model.Alerts expected model.Alerts
@ -151,6 +160,7 @@ func TestHandlerSendAll(t *testing.T) {
defer server2.Close() defer server2.Close()
h := New(&Options{}, prometheus.DefaultRegisterer) h := New(&Options{}, prometheus.DefaultRegisterer)
defer unregisterMetrics()
h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{ h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{
ams: []alertmanager{ ams: []alertmanager{
alertmanagerMock{ alertmanagerMock{
@ -218,6 +228,7 @@ func TestCustomDo(t *testing.T) {
}, nil }, nil
}, },
}, prometheus.DefaultRegisterer) }, prometheus.DefaultRegisterer)
defer unregisterMetrics()
h.sendOne(context.Background(), nil, testURL, []byte(testBody)) h.sendOne(context.Background(), nil, testURL, []byte(testBody))
@ -240,6 +251,7 @@ func TestExternalLabels(t *testing.T) {
}, },
}, },
}, prometheus.DefaultRegisterer) }, prometheus.DefaultRegisterer)
defer unregisterMetrics()
// This alert should get the external label attached. // This alert should get the external label attached.
h.Send(&model.Alert{ h.Send(&model.Alert{
@ -293,7 +305,8 @@ func TestHandlerRelabel(t *testing.T) {
Replacement: "renamed", Replacement: "renamed",
}, },
}, },
}) }, prometheus.DefaultRegisterer)
defer unregisterMetrics()
// This alert should be dropped due to the configuration // This alert should be dropped due to the configuration
h.Send(&model.Alert{ h.Send(&model.Alert{
@ -347,7 +360,8 @@ func TestHandlerQueueing(t *testing.T) {
h := New(&Options{ h := New(&Options{
QueueCapacity: 3 * maxBatchSize, QueueCapacity: 3 * maxBatchSize,
}) }, prometheus.DefaultRegisterer)
defer unregisterMetrics()
h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{ h.alertmanagers = append(h.alertmanagers, &alertmanagerSet{
ams: []alertmanager{ ams: []alertmanager{
alertmanagerMock{ alertmanagerMock{
@ -357,7 +371,7 @@ func TestHandlerQueueing(t *testing.T) {
cfg: &config.AlertmanagerConfig{ cfg: &config.AlertmanagerConfig{
Timeout: time.Second, Timeout: time.Second,
}, },
}, prometheus.DefaultRegisterer) })
var alerts model.Alerts var alerts model.Alerts
for i := range make([]struct{}, 20*maxBatchSize) { for i := range make([]struct{}, 20*maxBatchSize) {