2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-09-20 02:55:46 +08:00

Merge pull request #10 from tamird/cleanup-error-handler

TestErrorHandler: assert that the error handler runs
This commit is contained in:
Soheil Hassas Yeganeh 2016-02-22 22:47:19 -05:00
commit 95fd8b5c56
2 changed files with 13 additions and 8 deletions

View File

@ -6,6 +6,8 @@ go:
- 1.5
- 1.6
gobuild_args: -race
before_install:
- go get -u github.com/golang/lint/golint
- if [[ $TRAVIS_GO_VERSION == 1.5* ]]; then go get -u github.com/kisielk/errcheck; fi

View File

@ -10,6 +10,7 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
)
@ -212,15 +213,13 @@ func TestErrorHandler(t *testing.T) {
go runTestHTTPServer(errCh, httpl)
go safeServe(errCh, muxl)
firstErr := true
var errCount uint32
muxl.HandleError(func(err error) bool {
if !firstErr {
return true
if atomic.AddUint32(&errCount, 1) == 1 {
if _, ok := err.(ErrNotMatched); !ok {
t.Errorf("unexpected error: %v", err)
}
}
if _, ok := err.(ErrNotMatched); !ok {
t.Errorf("unexpected error: %v", err)
}
firstErr = false
return true
})
@ -229,7 +228,11 @@ func TestErrorHandler(t *testing.T) {
var num int
if err := c.Call("TestRPCRcvr.Test", rpcVal, &num); err == nil {
t.Error("rpc got a response")
// The connection is simply closed.
t.Errorf("unexpected rpc success after %d errors", atomic.LoadUint32(&errCount))
}
if atomic.LoadUint32(&errCount) == 0 {
t.Errorf("expected at least 1 error(s), got none")
}
}