fix race in unit test re logging (#17235)

Этот коммит содержится в:
Doug Lauder
2021-03-29 08:19:42 -04:00
коммит произвёл GitHub
родитель 217f614f2d
Коммит 1fb7f512ff
2 изменённых файлов: 5 добавлений и 7 удалений

Просмотреть файл

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

Просмотреть файл

@@ -88,7 +88,7 @@ func (tcp *Tcp) getConn() (net.Conn, error) {
if err == nil { if err == nil {
tcp.conn = conn tcp.conn = conn
tcp.monitor = make(chan struct{}) tcp.monitor = make(chan struct{})
go monitor(tcp.conn, tcp.monitor) go monitor(tcp.conn, tcp.monitor, Log)
} }
ch <- result{conn: conn, err: err} ch <- result{conn: conn, err: err}
}(ctx, connChan) }(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 // 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; // take a long time to detect a loss of connectivity on a socket when only writing;
// the writes simply fail without an error returned. // 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() addy := conn.RemoteAddr().String()
defer Log(LvlTcpLogTarget, "monitor exiting", String("addy", addy)) defer logFunc(LvlTcpLogTarget, "monitor exiting", String("addy", addy))
buf := make([]byte, 1) buf := make([]byte, 1)
for { for {
Log(LvlTcpLogTarget, "monitor loop", String("addy", addy)) logFunc(LvlTcpLogTarget, "monitor loop", String("addy", addy))
select { select {
case <-done: case <-done:
@@ -248,7 +248,7 @@ func monitor(conn net.Conn, done <-chan struct{}) {
} }
// Any other error closes the connection, forcing a reconnect. // 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() conn.Close()
return return
} }