From 1fb7f512ffb35b7a1386e240a0ab4d263564540c Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Mon, 29 Mar 2021 08:19:42 -0400 Subject: [PATCH] fix race in unit test re logging (#17235) --- shared/mlog/global_test.go | 2 -- shared/mlog/tcp.go | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/shared/mlog/global_test.go b/shared/mlog/global_test.go index 73ec73b49d..7da9e62aaa 100644 --- a/shared/mlog/global_test.go +++ b/shared/mlog/global_test.go @@ -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 diff --git a/shared/mlog/tcp.go b/shared/mlog/tcp.go index dc0f4cf419..d65b43ee8c 100644 --- a/shared/mlog/tcp.go +++ b/shared/mlog/tcp.go @@ -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 }