Merge pull request #2133 from dmcgowan/fix-notification-unit-test

[Carry #1990]Fix notification unit test
This commit is contained in:
Stephen Day 2017-01-10 11:08:51 -08:00 committed by GitHub
commit ff68ca391b

View file

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"mime" "mime"
"net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
@ -94,6 +95,21 @@ func TestHTTPSink(t *testing.T) {
var expectedMetrics EndpointMetrics var expectedMetrics EndpointMetrics
expectedMetrics.Statuses = make(map[string]int) expectedMetrics.Statuses = make(map[string]int)
closeL, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("unexpected error creating listener: %v", err)
}
defer closeL.Close()
go func() {
for {
c, err := closeL.Accept()
if err != nil {
return
}
c.Close()
}
}()
for _, tc := range []struct { for _, tc := range []struct {
events []Event // events to send events []Event // events to send
url string url string
@ -121,8 +137,8 @@ func TestHTTPSink(t *testing.T) {
failure: true, failure: true,
}, },
{ {
// Case where connection never goes through. // Case where connection is immediately closed
url: "http://shoudlntresolve/", url: closeL.Addr().String(),
failure: true, failure: true,
}, },
} { } {