diff --git a/test/integration/framework/etcd.go b/test/integration/framework/etcd.go index 25e2fbbfe11..7a6f8144be1 100644 --- a/test/integration/framework/etcd.go +++ b/test/integration/framework/etcd.go @@ -25,7 +25,6 @@ import ( "os" "os/exec" "strings" - "sync" "syscall" "testing" "time" @@ -84,7 +83,15 @@ func startEtcd(output io.Writer) (func(), error) { return stop, nil } -var initGRPCOnce sync.Once +func init() { + // Quiet etcd logs for integration tests + // Comment out to get verbose logs if desired. + // This has to be done before there are any goroutines + // active which use gRPC. During init is safe, albeit + // then also affects tests which don't use RunCustomEtcd + // (the place this was done before). + grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, os.Stderr)) +} // RunCustomEtcd starts a custom etcd instance for test purposes. func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url string, stopFn func(), err error) { @@ -151,12 +158,6 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url } } - // Quiet etcd logs for integration tests - // Comment out to get verbose logs if desired - initGRPCOnce.Do(func() { - grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, os.Stderr)) - }) - if err := cmd.Start(); err != nil { return "", nil, fmt.Errorf("failed to run etcd: %v", err) }