@@ -161,8 +161,19 @@ func isUnorderedLog(log *logMessage) bool {
161
161
// or close a connection first. Because of this, either log may be
162
162
// received in any order. To account for this behavior, we considered
163
163
// 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.
164
174
return msgStr == logger .ConnectionCheckoutFailed ||
165
- msgStr == logger .ConnectionClosed
175
+ msgStr == logger .ConnectionClosed ||
176
+ msgStr == logger .ConnectionPoolCleared
166
177
}
167
178
168
179
type logQueues struct {
@@ -251,8 +262,21 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error {
251
262
go func () {
252
263
defer close (errs )
253
264
265
+ // Record the message literals as they occur.
266
+ actualMessageSet := map [string ]bool {}
267
+
254
268
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
+ }
256
280
257
281
// Iterate over the unordered log messages and verify
258
282
// that at least one of them matches the actual log
@@ -272,6 +296,8 @@ func matchUnorderedLogs(ctx context.Context, logs logQueues) <-chan error {
272
296
if err != nil {
273
297
errs <- err
274
298
}
299
+
300
+ actualMessageSet [msgStr ] = true
275
301
}
276
302
}()
277
303
0 commit comments