Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2986 [master] Resolve failures in Race Detector Test #1392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mongo/integration/change_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func TestChangeStream_ReplicaSet(t *testing.T) {
require.NoError(mt, err, "failed to update idValue")
}()

nextCtx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
nextCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
t.Cleanup(cancel)

type splitEvent struct {
Expand Down
16 changes: 16 additions & 0 deletions mongo/integration/unified/client_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type clientEntity struct {

eventsCountLock sync.RWMutex
serverDescriptionChangedEventsCountLock sync.RWMutex
eventProcessMu sync.RWMutex

entityMap *EntityMap

Expand Down Expand Up @@ -471,6 +472,9 @@ func (c *clientEntity) processPoolEvent(evt *event.PoolEvent) {
}

func (c *clientEntity) processServerDescriptionChangedEvent(evt *event.ServerDescriptionChangedEvent) {
c.eventProcessMu.Lock()
defer c.eventProcessMu.Unlock()

if !c.getRecordEvents() {
return
}
Expand All @@ -487,6 +491,9 @@ func (c *clientEntity) processServerDescriptionChangedEvent(evt *event.ServerDes
}

func (c *clientEntity) processServerHeartbeatFailedEvent(evt *event.ServerHeartbeatFailedEvent) {
c.eventProcessMu.Lock()
defer c.eventProcessMu.Unlock()

if !c.getRecordEvents() {
return
}
Expand All @@ -499,6 +506,9 @@ func (c *clientEntity) processServerHeartbeatFailedEvent(evt *event.ServerHeartb
}

func (c *clientEntity) processServerHeartbeatStartedEvent(evt *event.ServerHeartbeatStartedEvent) {
c.eventProcessMu.Lock()
defer c.eventProcessMu.Unlock()

if !c.getRecordEvents() {
return
}
Expand All @@ -511,6 +521,9 @@ func (c *clientEntity) processServerHeartbeatStartedEvent(evt *event.ServerHeart
}

func (c *clientEntity) processServerHeartbeatSucceededEvent(evt *event.ServerHeartbeatSucceededEvent) {
c.eventProcessMu.Lock()
defer c.eventProcessMu.Unlock()

if !c.getRecordEvents() {
return
}
Expand All @@ -523,6 +536,9 @@ func (c *clientEntity) processServerHeartbeatSucceededEvent(evt *event.ServerHea
}

func (c *clientEntity) processTopologyDescriptionChangedEvent(evt *event.TopologyDescriptionChangedEvent) {
c.eventProcessMu.Lock()
defer c.eventProcessMu.Unlock()

if !c.getRecordEvents() {
return
}
Expand Down
25 changes: 20 additions & 5 deletions mongo/integration/unified/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package unified

import (
"sync"

"go.mongodb.org/mongo-driver/internal/logger"
)

Expand All @@ -20,9 +22,19 @@ type orderedLogMessage struct {
// Logger is the Sink used to captured log messages for logger verification in
// the unified spec tests.
type Logger struct {
// bufSize is the number of logs expected to be sent to the logger for a
// unified spec test.
bufSize int

// lastOrder increments each time the "Info" method is called, and is used to
// determine when to close the logQueue.
lastOrder int
logQueue chan orderedLogMessage
bufSize int

// orderMu guards the order value, which increments each time the "Info"
// method is called. This is necessary since "Info" could be called from
// multiple go routines, e.g. SDAM logs.
orderMu sync.RWMutex
logQueue chan orderedLogMessage
}

func newLogger(olm *observeLogMessages, bufSize int) *Logger {
Expand All @@ -44,14 +56,17 @@ func (log *Logger) Info(level int, msg string, args ...interface{}) {
return
}

defer func() { log.lastOrder++ }()

// 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 {
return
}

log.orderMu.Lock()
defer log.orderMu.Unlock()

defer func() { log.lastOrder++ }()

// Add the Diff back to the level, as there is no need to create a
// logging offset.
level = level + logger.DiffToInfo
Expand All @@ -68,7 +83,7 @@ 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 the order has reached the buffer size, then close the channel.
if log.lastOrder == log.bufSize {
close(log.logQueue)
}
Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/unified/unified_spec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (tc *TestCase) Run(ls LoggerSkipper) error {
}

// Count the number of expected log messages over all clients.
expectedLogCount := 0
var expectedLogCount int
for _, clientLog := range tc.ExpectLogMessages {
expectedLogCount += len(clientLog.LogMessages)
}
Expand Down
Loading