2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-10 03:31:52 +08:00

TestErrorHandler: assert that the error handler runs

Also fixes a race condition using an atomic and adds the race detector
to Travis CI.
This commit is contained in:
Tamir Duberstein 2016-02-21 13:50:28 -05:00
parent 4796322bac
commit 15b1cf90b1
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")
}
}