agent: fix data race in tests caused by grpc log init
grpclog.SetLoggerV2 is meant to be called only once before any gRPC requests are received, but each test that uses TestAgent will call NewBaseDeps again. Use a sync.Once to prevent the grpc logging from being re-initialized by each test. This will mean that a test can't use a fake logger to capture logs from the gRPC server.
This commit is contained in:
parent
43b14bf57f
commit
1a6bff1109
|
@ -66,7 +66,10 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error)
|
|||
if err != nil {
|
||||
return d, err
|
||||
}
|
||||
grpclog.SetLoggerV2(logging.NewGRPCLogger(cfg.Logging.LogLevel, d.Logger))
|
||||
|
||||
grpcLogInitOnce.Do(func() {
|
||||
grpclog.SetLoggerV2(logging.NewGRPCLogger(cfg.Logging.LogLevel, d.Logger))
|
||||
})
|
||||
|
||||
for _, w := range result.Warnings {
|
||||
d.Logger.Warn(w)
|
||||
|
@ -123,6 +126,10 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error)
|
|||
return d, nil
|
||||
}
|
||||
|
||||
// grpcLogInitOnce because the test suite will call NewBaseDeps in many tests and
|
||||
// causes data races when it is re-initialized.
|
||||
var grpcLogInitOnce sync.Once
|
||||
|
||||
func newConnPool(config *config.RuntimeConfig, logger hclog.Logger, tls *tlsutil.Configurator) *pool.ConnPool {
|
||||
var rpcSrcAddr *net.TCPAddr
|
||||
if !ipaddr.IsAny(config.RPCBindAddr) {
|
||||
|
|
Loading…
Reference in New Issue