From 7d13bebd84fc81ba4e345879789ae63dadcac1fc Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 13 Jun 2023 15:55:55 -0500 Subject: [PATCH] GODRIVER-2855 Relax closed, cleared, checkout conditions on logger verification (#1287) --- .../unified/logger_verification.go | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/mongo/integration/unified/logger_verification.go b/mongo/integration/unified/logger_verification.go index f0c971db91..ad13d097fb 100644 --- a/mongo/integration/unified/logger_verification.go +++ b/mongo/integration/unified/logger_verification.go @@ -161,8 +161,19 @@ func isUnorderedLog(log *logMessage) bool { // or close a connection first. Because of this, either log may be // received in any order. To account for this behavior, we considered // both logs to be "unordered". + // + // The connection pool must clear before the connection is closed. + // However, either of these conditions are valid: + // + // 1. connection checkout failed > connection pool cleared + // 2. connection pool cleared > connection checkout failed + // + // Therefore, the ConnectionPoolCleared literal is added to the + // unordered list. The check for cleared > closed is made in the + // matching logic. return msgStr == logger.ConnectionCheckoutFailed || - msgStr == logger.ConnectionClosed + msgStr == logger.ConnectionClosed || + msgStr == logger.ConnectionPoolCleared } type logQueues struct { @@ -251,8 +262,21 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error { go func() { defer close(errs) + // Record the message literals as they occur. + actualMessageSet := map[string]bool{} + for actual := range logs.unordered { - var err error + msg, err := actual.Data.LookupErr(logger.KeyMessage) + if err != nil { + errs <- fmt.Errorf("could not lookup message from unordered log: %w", err) + + break + } + + msgStr := msg.StringValue() + if msgStr == logger.ConnectionPoolCleared && actualMessageSet[logger.ConnectionClosed] { + errs <- fmt.Errorf("connection has been closed before the pool could clear") + } // Iterate over the unordered log messages and verify // that at least one of them matches the actual log @@ -272,6 +296,8 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error { if err != nil { errs <- err } + + actualMessageSet[msgStr] = true } }()