test: disable leakcheck after the first failure (#2563)

This commit is contained in:
Doug Fawley
2019-01-14 15:40:20 -08:00
committed by GitHub
parent f647b6facb
commit 98a94b0cb0
2 changed files with 37 additions and 2 deletions

View File

@ -19,6 +19,7 @@
package grpc
import (
"sync/atomic"
"testing"
"google.golang.org/grpc/internal/grpctest"
@ -27,8 +28,25 @@ import (
type s struct{}
var lcFailed uint32
type errorer struct {
t *testing.T
}
func (e errorer) Errorf(format string, args ...interface{}) {
atomic.StoreUint32(&lcFailed, 1)
e.t.Errorf(format, args...)
}
func (s) Teardown(t *testing.T) {
leakcheck.Check(t)
if atomic.LoadUint32(&lcFailed) == 1 {
return
}
leakcheck.Check(errorer{t: t})
if atomic.LoadUint32(&lcFailed) == 1 {
t.Log("Leak check disabled for future tests")
}
}
func Test(t *testing.T) {

View File

@ -80,8 +80,25 @@ func init() {
type s struct{}
var lcFailed uint32
type errorer struct {
t *testing.T
}
func (e errorer) Errorf(format string, args ...interface{}) {
atomic.StoreUint32(&lcFailed, 1)
e.t.Errorf(format, args...)
}
func (s) Teardown(t *testing.T) {
leakcheck.Check(t)
if atomic.LoadUint32(&lcFailed) == 1 {
return
}
leakcheck.Check(errorer{t: t})
if atomic.LoadUint32(&lcFailed) == 1 {
t.Log("Leak check disabled for future tests")
}
}
func Test(t *testing.T) {