Fix acceptance test

This commit is contained in:
Fabian Reinartz 2015-10-01 22:15:27 +02:00
parent 7b0820a205
commit 152f811227
2 changed files with 13 additions and 24 deletions

View File

@ -52,27 +52,16 @@ func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest {
return test return test
} }
var freeAdresses []string
func freeAddress() string { func freeAddress() string {
if len(freeAdresses) == 0 { // Let the OS allocate a free address, close it and hope
for i := 0; i < 100; i++ { // it is still free when starting Alertmanager.
// Let the OS allocate a free address, close it and hope l, err := net.Listen("tcp", ":0")
// it is still free when starting Alertmanager. if err != nil {
l, err := net.Listen("tcp", ":0") panic(err)
if err != nil {
panic(err)
}
defer l.Close()
freeAdresses = append(freeAdresses, l.Addr().String())
}
} }
defer l.Close()
next := freeAdresses[0] return l.Addr().String()
freeAdresses = freeAdresses[1:]
return next
} }
// Alertmanager returns a new structure that allows starting an instance // Alertmanager returns a new structure that allows starting an instance
@ -196,7 +185,7 @@ func (am *Alertmanager) Push(at float64, alerts ...*TestAlert) {
return return
} }
resp, err := http.Post(fmt.Sprintf("http://%s/api/alerts", am.addr), "application/json", &buf) resp, err := http.Post(fmt.Sprintf("http://%s/api/v1/alerts", am.addr), "application/json", &buf)
if err != nil { if err != nil {
am.t.Error(err) am.t.Error(err)
return return
@ -253,11 +242,11 @@ func (am *Alertmanager) runActions() {
wg.Add(len(fs)) wg.Add(len(fs))
for _, f := range fs { for _, f := range fs {
go func() { go func(f func()) {
time.Sleep(ts.Sub(time.Now())) time.Sleep(ts.Sub(time.Now()))
f() f()
wg.Done() wg.Done()
}() }(f)
} }
} }

View File

@ -76,7 +76,7 @@ func TestSilencing(t *testing.T) {
at := NewAcceptanceTest(t, &AcceptanceOpts{ at := NewAcceptanceTest(t, &AcceptanceOpts{
Tolerance: 150 * time.Millisecond, Tolerance: 150 * time.Millisecond,
Config: somethingConfig, Config: silenceConfig,
}) })
am := at.Alertmanager() am := at.Alertmanager()
@ -86,7 +86,7 @@ func TestSilencing(t *testing.T) {
// No repeat interval is configured. Thus, we receive an alert // No repeat interval is configured. Thus, we receive an alert
// notification every second. // notification every second.
am.Push(At(1), Alert("alertname", "test122").Active(1)) am.Push(At(1), Alert("alertname", "test1").Active(1))
am.Push(At(1), Alert("alertname", "test2").Active(1)) am.Push(At(1), Alert("alertname", "test2").Active(1))
co.Want(Between(2, 2.5), co.Want(Between(2, 2.5),
@ -111,7 +111,7 @@ func TestSilencing(t *testing.T) {
) )
// Start the flow as defined above and run the checks afterwards. // Start the flow as defined above and run the checks afterwards.
// at.Run() at.Run()
} }
var batchConfig = ` var batchConfig = `