Fail integration tests on race (#990)

This commit is contained in:
Egon Elbre 2019-01-08 18:59:09 +02:00 committed by GitHub
parent 9e55a7209d
commit 7721c594a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 4 deletions

View File

@ -72,9 +72,9 @@ matrix:
- source scripts/install-awscli.sh
- go install -race storj.io/storj/cmd/{storj-sdk,satellite,storagenode,uplink,gateway,certificates,captplanet}
script:
- make test-storj-sdk
- make test-certificate-signing
- make test-captplanet
- make test-storj-sdk |& go run scripts/fail-on-race.go
- make test-certificate-signing |& go run scripts/fail-on-race.go
- make test-captplanet |& go run scripts/fail-on-race.go
### Docker tests ###
- env: MODE=docker
@ -85,7 +85,7 @@ matrix:
install:
- source scripts/install-awscli.sh
script:
- make test-all-in-one
- make test-all-in-one |& go run scripts/fail-on-race.go
### windows tests ###
- env: MODE=windows-tests

55
scripts/fail-on-race.go Normal file
View File

@ -0,0 +1,55 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// +build ignore
package main
import (
"bytes"
"io"
"os"
)
// fail-on-race detects for keyword "DATA RACE" in output
// and returns error code, if the output contains it.
func main() {
var buffer [8192]byte
raceDetected := false
search := []byte("DATA RACE")
start := 0
for {
n, readErr := os.Stdin.Read(buffer[start:])
end := start + n
_, writeErr := os.Stdout.Write(buffer[start:end])
if writeErr != nil {
os.Stderr.Write([]byte(writeErr.Error()))
os.Exit(2)
}
if bytes.Contains(buffer[:end], search) {
raceDetected = true
break
}
// copy buffer tail to the beginning of the content
if end > len(search) {
copy(buffer[:], buffer[end-len(search):end])
start = len(search)
}
if readErr != nil {
break
}
}
_, _ = io.Copy(os.Stdout, os.Stdin)
if raceDetected {
os.Stderr.Write([]byte("\nTest failed due to data race.\n"))
os.Exit(1)
}
}