Skip to content

Commit

Permalink
tests: disable running tests in parallel in Travis CI (#109)
Browse files Browse the repository at this point in the history
Travis CI is slow and this makes tests that have timeouts flaky. We
could increase the timeouts, but that would slow the feedback cycle of
local development. Instead this commit disables running tests in
parallel when the 'travis' build tag is provided (I had some spicier
names for it, but I considering this is OSS 'travis' will do).

Note: we do not rely on tests being parallel to identify race conditions
- we do that explicitly and often.
  • Loading branch information
charlievieth authored Sep 26, 2020
1 parent 503d0e4 commit 656a958
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ go:
- "1.14.x"
- "1.15.x"

# The "travis" build tag disables running tests in parallel.
# We this because Travis is slow (and sadly some of the tests
# tests must be timeout based).
env:
- GOFLAGS='-tags=travis'

before_install: mkdir -p $GOPATH/bin
install: make install
script: make lint quick test
6 changes: 3 additions & 3 deletions net_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func testNetSinkReconnect(t *testing.T, protocol string) {
if testing.Short() {
t.Skip("Skipping: short test")
}
t.Parallel()
Parallel(t)

const expected = "counter:1|c\n"

Expand Down Expand Up @@ -692,7 +692,7 @@ func testNetSinkReconnectFailure(t *testing.T, protocol string) {
if testing.Short() {
t.Skip("Skipping: short test")
}
t.Parallel()
Parallel(t)

ts, sink := setupTestNetSink(t, protocol, true)
defer ts.Close()
Expand Down Expand Up @@ -794,7 +794,7 @@ func buildBinary(t testing.TB, path string) (string, func()) {
}

func testNetSinkIntegration(t *testing.T, protocol string) {
t.Parallel()
Parallel(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
4 changes: 2 additions & 2 deletions net_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func reconnectRetry(t testing.TB, fn func() error) {
}

func TestReconnectRetryTCP(t *testing.T) {
t.Parallel()
Parallel(t)

l1, err := net.ListenTCP("tcp", &net.TCPAddr{
IP: net.IPv4(127, 0, 0, 1),
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestReconnectRetryTCP(t *testing.T) {
}

func TestReconnectRetryUDP(t *testing.T) {
t.Parallel()
Parallel(t)

l1, err := net.ListenUDP("udp", &net.UDPAddr{
IP: net.IPv4(127, 0, 0, 1),
Expand Down
8 changes: 8 additions & 0 deletions parallel_ci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build travis

package stats

import "testing"

// Travis CI is really slow - so don't run tests in parallel.
func Parallel(t *testing.T) { /* no-op */ }
7 changes: 7 additions & 0 deletions parallel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !travis

package stats

import "testing"

func Parallel(t *testing.T) { t.Parallel() }
2 changes: 1 addition & 1 deletion stat_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestHttpHandler_ServeHTTP(t *testing.T) {
t.Parallel()
Parallel(t)

sink := mock.NewSink()
store := NewStore(sink, false)
Expand Down
4 changes: 2 additions & 2 deletions stat_handler_wrapper_1.7_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestHTTPHandler_WrapResponse(t *testing.T) {
t.Parallel()
Parallel(t)

tests := []http.ResponseWriter{
struct {
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestHTTPHandler_WrapResponse(t *testing.T) {
for i, test := range tests {
tc := test
t.Run(fmt.Sprint("test:", i), func(t *testing.T) {
t.Parallel()
Parallel(t)

_, canFlush := tc.(http.Flusher)
_, canHijack := tc.(http.Hijacker)
Expand Down

0 comments on commit 656a958

Please sign in to comment.