fix race in unit test re logging (#17235)

This commit is contained in:
Doug Lauder
2021-03-29 08:19:42 -04:00
committed by GitHub
parent 217f614f2d
commit 1fb7f512ff
2 changed files with 5 additions and 7 deletions

View File

@@ -28,8 +28,6 @@ func TestLoggingBeforeInitialized(t *testing.T) {
}
func TestLoggingAfterInitialized(t *testing.T) {
t.Skip("Racy test: MM-34271")
testCases := []struct {
Description string
LoggerConfiguration *mlog.LoggerConfiguration

View File

@@ -88,7 +88,7 @@ func (tcp *Tcp) getConn() (net.Conn, error) {
if err == nil {
tcp.conn = conn
tcp.monitor = make(chan struct{})
go monitor(tcp.conn, tcp.monitor)
go monitor(tcp.conn, tcp.monitor, Log)
}
ch <- result{conn: conn, err: err}
}(ctx, connChan)
@@ -221,13 +221,13 @@ func (tcp *Tcp) Write(rec *logr.LogRec) error {
// This is needed because TCP target uses a write only socket and Linux systems
// take a long time to detect a loss of connectivity on a socket when only writing;
// the writes simply fail without an error returned.
func monitor(conn net.Conn, done <-chan struct{}) {
func monitor(conn net.Conn, done <-chan struct{}, logFunc LogFuncCustom) {
addy := conn.RemoteAddr().String()
defer Log(LvlTcpLogTarget, "monitor exiting", String("addy", addy))
defer logFunc(LvlTcpLogTarget, "monitor exiting", String("addy", addy))
buf := make([]byte, 1)
for {
Log(LvlTcpLogTarget, "monitor loop", String("addy", addy))
logFunc(LvlTcpLogTarget, "monitor loop", String("addy", addy))
select {
case <-done:
@@ -248,7 +248,7 @@ func monitor(conn net.Conn, done <-chan struct{}) {
}
// Any other error closes the connection, forcing a reconnect.
Log(LvlTcpLogTarget, "monitor closing connection", Err(err))
logFunc(LvlTcpLogTarget, "monitor closing connection", Err(err))
conn.Close()
return
}