Skip to content

Commit 7d13beb

Browse files
GODRIVER-2855 Relax closed, cleared, checkout conditions on logger verification (#1287)
1 parent 9a4ad54 commit 7d13beb

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

mongo/integration/unified/logger_verification.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,19 @@ func isUnorderedLog(log *logMessage) bool {
161161
// or close a connection first. Because of this, either log may be
162162
// received in any order. To account for this behavior, we considered
163163
// both logs to be "unordered".
164+
//
165+
// The connection pool must clear before the connection is closed.
166+
// However, either of these conditions are valid:
167+
//
168+
// 1. connection checkout failed > connection pool cleared
169+
// 2. connection pool cleared > connection checkout failed
170+
//
171+
// Therefore, the ConnectionPoolCleared literal is added to the
172+
// unordered list. The check for cleared > closed is made in the
173+
// matching logic.
164174
return msgStr == logger.ConnectionCheckoutFailed ||
165-
msgStr == logger.ConnectionClosed
175+
msgStr == logger.ConnectionClosed ||
176+
msgStr == logger.ConnectionPoolCleared
166177
}
167178

168179
type logQueues struct {
@@ -251,8 +262,21 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error {
251262
go func() {
252263
defer close(errs)
253264

265+
// Record the message literals as they occur.
266+
actualMessageSet := map[string]bool{}
267+
254268
for actual := range logs.unordered {
255-
var err error
269+
msg, err := actual.Data.LookupErr(logger.KeyMessage)
270+
if err != nil {
271+
errs <- fmt.Errorf("could not lookup message from unordered log: %w", err)
272+
273+
break
274+
}
275+
276+
msgStr := msg.StringValue()
277+
if msgStr == logger.ConnectionPoolCleared && actualMessageSet[logger.ConnectionClosed] {
278+
errs <- fmt.Errorf("connection has been closed before the pool could clear")
279+
}
256280

257281
// Iterate over the unordered log messages and verify
258282
// that at least one of them matches the actual log
@@ -272,6 +296,8 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error {
272296
if err != nil {
273297
errs <- err
274298
}
299+
300+
actualMessageSet[msgStr] = true
275301
}
276302
}()
277303

0 commit comments

Comments
 (0)