* Fix flaky tests in several notifiers
- Non-mocked time in sensu go tests
- Close server in Slack tests
- Use a mutex for writing responses in the fake slack server
* Remove mutex at the fake slack server
(cherry picked from commit bdab1d1f1f)
Co-authored-by: gotjosh <josue@grafana.com>
This commit is contained in:
co-authored by
gotjosh
parent
43748f2578
commit
ffde9fcfcf
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
@@ -120,7 +119,7 @@ func (sn *SensuGoNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"output": tmpl(sn.Message),
|
"output": tmpl(sn.Message),
|
||||||
"issued": time.Now().Unix(),
|
"issued": timeNow().Unix(),
|
||||||
"interval": 86400,
|
"interval": 86400,
|
||||||
"status": status,
|
"status": status,
|
||||||
"handlers": handlers,
|
"handlers": handlers,
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSensuGoNotifier(t *testing.T) {
|
func TestSensuGoNotifier(t *testing.T) {
|
||||||
|
constNow := time.Now()
|
||||||
|
defer mockTimeNow(constNow)()
|
||||||
|
|
||||||
tmpl := templateForTests(t)
|
tmpl := templateForTests(t)
|
||||||
|
|
||||||
externalURL, err := url.Parse("http://localhost")
|
externalURL, err := url.Parse("http://localhost")
|
||||||
@@ -60,7 +63,7 @@ func TestSensuGoNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"output": "**Firing**\n\nValue: <no value>\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
"output": "**Firing**\n\nValue: <no value>\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n",
|
||||||
"issued": time.Now().Unix(),
|
"issued": timeNow().Unix(),
|
||||||
"interval": 86400,
|
"interval": 86400,
|
||||||
"status": 2,
|
"status": 2,
|
||||||
"handlers": nil,
|
"handlers": nil,
|
||||||
@@ -107,7 +110,7 @@ func TestSensuGoNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"output": "2 alerts are firing, 0 are resolved",
|
"output": "2 alerts are firing, 0 are resolved",
|
||||||
"issued": time.Now().Unix(),
|
"issued": timeNow().Unix(),
|
||||||
"interval": 86400,
|
"interval": 86400,
|
||||||
"status": 2,
|
"status": 2,
|
||||||
"handlers": []string{"myhandler"},
|
"handlers": []string{"myhandler"},
|
||||||
|
|||||||
@@ -303,6 +303,7 @@ func TestSendSlackRequest(t *testing.T) {
|
|||||||
_, err := w.Write([]byte(test.slackResponse))
|
_, err := w.Write([]byte(test.slackResponse))
|
||||||
require.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
}))
|
}))
|
||||||
|
defer server.Close()
|
||||||
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
|
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
|
||||||
require.NoError(tt, err)
|
require.NoError(tt, err)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user