Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
If running test behide a proxy, we may get the error code
403 Forbidden which will fail line 135 for the last testcase.

Detail:
```
metrics not as expected: notifications.EndpointMetrics{Pending:0,
Events:0, Successes:4, Failures:0, Errors:0,
Statuses:map[string]int{"307 Temporary Redirect":0, "400 Bad Request":0,
"403 Forbidden":0, "200 OK":4}} !=
notifications.EndpointMetrics{Pending:0, Events:0, Successes:4,
Failures:0, Errors:0, Statuses:map[string]int{"400 Bad Request":0, "200
OK":4, "307 Temporary Redirect":0}}
```

Immediate close will fix that

Signed-off-by: Hu Keping <[email protected]>
Signed-off-by: Derek McGowan <[email protected]>
  • Loading branch information
dmcgowan committed Jan 10, 2017
1 parent 129ad8e commit efc3209
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions notifications/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"mime"
"net"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -94,6 +95,21 @@ func TestHTTPSink(t *testing.T) {
var expectedMetrics EndpointMetrics
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 {
events []Event // events to send
url string
Expand Down Expand Up @@ -121,8 +137,8 @@ func TestHTTPSink(t *testing.T) {
failure: true,
},
{
// Case where connection never goes through.
url: "http://shoudlntresolve/",
// Case where connection is immediately closed
url: closeL.Addr().String(),
failure: true,
},
} {
Expand Down

0 comments on commit efc3209

Please sign in to comment.