Merge pull request #12611 from ptabor/20210111-fix-flakes

e2e tests flakes & leaks fixes: In particular TestIssue6361
This commit is contained in:
Jingyi Hu
2021-01-12 21:26:54 +08:00
committed by GitHub
16 changed files with 85 additions and 54 deletions

View File

@@ -40,6 +40,26 @@ func (cfg Config) GetLogger() *zap.Logger {
// for testing
var grpcLogOnce = new(sync.Once)
func setupGrpcLogging(debug bool, config zap.Config) {
grpcLogOnce.Do(func() {
// debug true, enable info, warning, error
// debug false, only discard info
if debug {
var gl grpclog.LoggerV2
gl, err := logutil.NewGRPCLoggerV2(config)
if err == nil {
grpclog.SetLoggerV2(gl)
}
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
})
}
func SetupGrpcLoggingForTest(debug bool) {
setupGrpcLogging(debug, zap.NewDevelopmentConfig())
}
// setupLogging initializes etcd logging.
// Must be called after flag parsing or finishing configuring embed.Config.
func (cfg *Config) setupLogging() error {
@@ -106,19 +126,7 @@ func (cfg *Config) setupLogging() error {
c.loggerConfig = &copied
c.loggerCore = nil
c.loggerWriteSyncer = nil
grpcLogOnce.Do(func() {
// debug true, enable info, warning, error
// debug false, only discard info
if cfg.LogLevel == "debug" {
var gl grpclog.LoggerV2
gl, err = logutil.NewGRPCLoggerV2(copied)
if err == nil {
grpclog.SetLoggerV2(gl)
}
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
})
setupGrpcLogging(cfg.LogLevel == "debug", copied)
return nil
}
}

View File

@@ -18,7 +18,6 @@ import (
"reflect"
"testing"
"time"
"unsafe"
"go.etcd.io/etcd/pkg/v3/testutil"
)
@@ -102,7 +101,7 @@ func TestNodeExternClone(t *testing.T) {
}
func sameSlice(a, b []*NodeExtern) bool {
ah := (*reflect.SliceHeader)(unsafe.Pointer(&a))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
return *ah == *bh
va := reflect.ValueOf(a)
vb := reflect.ValueOf(b)
return va.Len() == vb.Len() && va.Pointer() == vb.Pointer()
}