mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-14 11:31:28 +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:
parent
4796322bac
commit
15b1cf90b1
@ -6,6 +6,8 @@ go:
|
|||||||
- 1.5
|
- 1.5
|
||||||
- 1.6
|
- 1.6
|
||||||
|
|
||||||
|
gobuild_args: -race
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get -u github.com/golang/lint/golint
|
- go get -u github.com/golang/lint/golint
|
||||||
- if [[ $TRAVIS_GO_VERSION == 1.5* ]]; then go get -u github.com/kisielk/errcheck; fi
|
- if [[ $TRAVIS_GO_VERSION == 1.5* ]]; then go get -u github.com/kisielk/errcheck; fi
|
||||||
|
19
cmux_test.go
19
cmux_test.go
@ -10,6 +10,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -212,15 +213,13 @@ func TestErrorHandler(t *testing.T) {
|
|||||||
go runTestHTTPServer(errCh, httpl)
|
go runTestHTTPServer(errCh, httpl)
|
||||||
go safeServe(errCh, muxl)
|
go safeServe(errCh, muxl)
|
||||||
|
|
||||||
firstErr := true
|
var errCount uint32
|
||||||
muxl.HandleError(func(err error) bool {
|
muxl.HandleError(func(err error) bool {
|
||||||
if !firstErr {
|
if atomic.AddUint32(&errCount, 1) == 1 {
|
||||||
return true
|
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
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -229,7 +228,11 @@ func TestErrorHandler(t *testing.T) {
|
|||||||
|
|
||||||
var num int
|
var num int
|
||||||
if err := c.Call("TestRPCRcvr.Test", rpcVal, &num); err == nil {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user