Skip to content

Commit

Permalink
Blacklist additional errors that shouldn't be logged by event stream …
Browse files Browse the repository at this point in the history
…test server. (#3052)
  • Loading branch information
skmcgrail committed Dec 24, 2019
1 parent 7122d08 commit b88d4f8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions private/protocol/eventstream/eventstreamtest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
"strings"
"sync"
"testing"
"time"
Expand All @@ -22,6 +23,11 @@ import (
"golang.org/x/net/http2"
)

const (
errClientDisconnected = "client disconnected"
errStreamClosed = "http2: stream closed"
)

// ServeEventStream provides serving EventStream messages from a HTTP server to
// the client. The events are sent sequentially to the client without delay.
type ServeEventStream struct {
Expand Down Expand Up @@ -93,14 +99,24 @@ func (s *ServeEventStream) serveBiDirectionalStream(w http.ResponseWriter, r *ht
}
wg.Wait()

if err != nil {
switch err.(type) {
case http2.StreamError:
break
default:
s.T.Error(err.Error())
if err != nil && isError(err) {
s.T.Error(err.Error())
}
}

func isError(err error) bool {
switch err.(type) {
case http2.StreamError:
return false
}

for _, s := range []string{errClientDisconnected, errStreamClosed} {
if strings.Contains(err.Error(), s) {
return false
}
}

return true
}

func (s ServeEventStream) readEvents(ctx context.Context, r *http.Request) error {
Expand Down

0 comments on commit b88d4f8

Please sign in to comment.