diff --git a/mongo/integration/unified/context.go b/mongo/integration/unified/context.go index 5a85aee825..d97abaf023 100644 --- a/mongo/integration/unified/context.go +++ b/mongo/integration/unified/context.go @@ -37,7 +37,7 @@ const ( func newTestContext( ctx context.Context, entityMap *EntityMap, - expectedLogMessageCount uint64, + expectedLogMessageCount int, hasOperationalFailPoint bool, ) context.Context { ctx = context.WithValue(ctx, operationalFailPointKey, hasOperationalFailPoint) @@ -84,6 +84,6 @@ func entities(ctx context.Context) *EntityMap { return ctx.Value(entitiesKey).(*EntityMap) } -func expectedLogMessageCount(ctx context.Context) uint64 { - return ctx.Value(expectedLogMessageCountKey).(uint64) +func expectedLogMessageCount(ctx context.Context) int { + return ctx.Value(expectedLogMessageCountKey).(int) } diff --git a/mongo/integration/unified/logger.go b/mongo/integration/unified/logger.go index 8760fff9d2..b2e8a28b7c 100644 --- a/mongo/integration/unified/logger.go +++ b/mongo/integration/unified/logger.go @@ -7,7 +7,6 @@ package unified import ( - "sync" "sync/atomic" "go.mongodb.org/mongo-driver/internal/logger" @@ -23,13 +22,12 @@ type orderedLogMessage struct { // Logger is the Sink used to captured log messages for logger verification in // the unified spec tests. type Logger struct { - bufSize uint64 - lastOrder uint64 + bufSize int + lastOrder int32 logQueue chan orderedLogMessage - mu sync.RWMutex } -func newLogger(olm *observeLogMessages, bufSize uint64) *Logger { +func newLogger(olm *observeLogMessages, bufSize int) *Logger { if olm == nil { return nil } @@ -44,18 +42,13 @@ func newLogger(olm *observeLogMessages, bufSize uint64) *Logger { // Info implements the logger.Sink interface's "Info" method for printing log // messages. func (log *Logger) Info(level int, msg string, args ...interface{}) { - log.mu.Lock() - defer log.mu.Unlock() - if log.logQueue == nil { return } - defer func() { atomic.AddUint64(&log.lastOrder, 1) }() - // If the order is greater than the buffer size, we must return. This // would indicate that the logQueue channel has been closed. - if log.lastOrder > log.bufSize { + if log.lastOrder > int32(log.bufSize) { return } @@ -75,10 +68,12 @@ func (log *Logger) Info(level int, msg string, args ...interface{}) { logMessage: logMessage, } - // If the order has reached the buffer size, then close the channe. - if log.lastOrder == log.bufSize { + // If the order has reached the buffer size, then close the channel. + if log.lastOrder == int32(log.bufSize) { close(log.logQueue) } + + atomic.AddInt32(&log.lastOrder, 1) } // Error implements the logger.Sink interface's "Error" method for printing log diff --git a/mongo/integration/unified/unified_spec_runner.go b/mongo/integration/unified/unified_spec_runner.go index 401e220184..7b92d07204 100644 --- a/mongo/integration/unified/unified_spec_runner.go +++ b/mongo/integration/unified/unified_spec_runner.go @@ -224,9 +224,9 @@ func (tc *TestCase) Run(ls LoggerSkipper) error { } // Count the number of expected log messages over all clients. - var expectedLogCount uint64 + var expectedLogCount int for _, clientLog := range tc.ExpectLogMessages { - expectedLogCount += uint64(len(clientLog.LogMessages)) + expectedLogCount += len(clientLog.LogMessages) } testCtx := newTestContext(context.Background(), tc.entities, expectedLogCount, tc.setsFailPoint())