diff --git a/.travis.yml b/.travis.yml index 074b049..f7d6791 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ go: - 1.12.x env: - global: - # - GOTFLAGS="-race" matrix: - BUILD_DEPTYPE=gomod @@ -16,8 +14,10 @@ env: install: - true +# run tests with and without race detection script: - bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh) + - GOTFLAGS="-race" bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh) cache: directories: diff --git a/go.mod b/go.mod index 8f5dc94..8cc218f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.12 require ( github.com/ipfs/go-log v0.0.1 + github.com/jbenet/go-detect-race v0.0.0-20150302022421-3463798d9574 github.com/libp2p/go-libp2p-crypto v0.0.1 github.com/libp2p/go-libp2p-peer v0.1.0 github.com/libp2p/go-libp2p-transport v0.0.5-0.20190506231221-045097a6a962 diff --git a/go.sum b/go.sum index 8b544ac..f6b0643 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,8 @@ github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIyk github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/jbenet/go-detect-race v0.0.0-20150302022421-3463798d9574 h1:Pxjl8Wn3cCU7nB/MCmPEUMbjMHxXFqODW6rce0jpxB4= +github.com/jbenet/go-detect-race v0.0.0-20150302022421-3463798d9574/go.mod h1:gynVu6LUw+xMXD3XEvjHQcIbJkWEamnGjJDebRHqTd0= github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw= github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/transport_test.go b/transport_test.go index c88edf1..167bd84 100644 --- a/transport_test.go +++ b/transport_test.go @@ -5,6 +5,7 @@ import ( "runtime" "testing" + detectrace "github.com/jbenet/go-detect-race" peer "github.com/libp2p/go-libp2p-peer" tpt "github.com/libp2p/go-libp2p-transport" utils "github.com/libp2p/go-libp2p-transport/test" @@ -15,34 +16,41 @@ import ( // in order to disable some tests while we investigate performance issues when // running the tests on resource restricted environments like the Travis CI. -var Subtests = []func(t *testing.T, ta, tb tpt.Transport, maddr ma.Multiaddr, peerA peer.ID){ - utils.SubtestProtocols, - utils.SubtestBasic, - - utils.SubtestCancel, - utils.SubtestPingPong, - - // Stolen from the stream muxer test suite. - utils.SubtestStress1Conn1Stream1Msg, - utils.SubtestStress1Conn1Stream100Msg, - utils.SubtestStress1Conn100Stream100Msg, - utils.SubtestStress50Conn10Stream50Msg, - utils.SubtestStress1Conn1000Stream10Msg, - utils.SubtestStress1Conn100Stream100Msg10MB, - utils.SubtestStreamOpenStress, - utils.SubtestStreamReset, -} - func getFunctionName(i interface{}) string { return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() } func SubtestTransport(t *testing.T, ta, tb tpt.Transport, addr string, peerA peer.ID) { + subtests := []func(t *testing.T, ta, tb tpt.Transport, maddr ma.Multiaddr, peerA peer.ID){} + + if detectrace.WithRace() { + subtests = []func(t *testing.T, ta, tb tpt.Transport, maddr ma.Multiaddr, peerA peer.ID){ + utils.SubtestProtocols, + utils.SubtestBasic, + + utils.SubtestCancel, + utils.SubtestPingPong, + + // Stolen from the stream muxer test suite. + utils.SubtestStress1Conn1Stream1Msg, + } + } else { + subtests = []func(t *testing.T, ta, tb tpt.Transport, maddr ma.Multiaddr, peerA peer.ID){ + utils.SubtestStress1Conn1Stream100Msg, + utils.SubtestStress1Conn100Stream100Msg, + utils.SubtestStress50Conn10Stream50Msg, + utils.SubtestStress1Conn1000Stream10Msg, + utils.SubtestStress1Conn100Stream100Msg10MB, + utils.SubtestStreamOpenStress, + utils.SubtestStreamReset, + } + } + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Fatal(err) } - for _, f := range Subtests { + for _, f := range subtests { t.Run(getFunctionName(f), func(t *testing.T) { f(t, ta, tb, maddr, peerA) })