Blacklist additional errors that shouldn't be logged by event stream test server.
@@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptest"
"reflect"
+ "strings"
"sync"
"testing"
"time"
@@ -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 {
@@ -93,14 +99,24 @@ func (s *ServeEventStream) serveBiDirectionalStream(w http.ResponseWriter, r *ht
}
wg.Wait()
- if err != nil {
+ if err != nil && isError(err) {
+ s.T.Error(err.Error())
+ }
+}
+
+func isError(err error) bool {
switch err.(type) {
case http2.StreamError:
- break
- default:
- s.T.Error(err.Error())
+ 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 {
