Run basic tests with race detector

This commit is contained in:
backkem 2019-05-07 13:49:22 +02:00 committed by Michiel De Backker
parent b10960bfd6
commit 2766c65c13
4 changed files with 32 additions and 21 deletions

View File

@ -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:

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)
})