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 Resolve failures in Race Detector Test #1380

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 10 additions & 8 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/atomic"

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

Expand All @@ -20,9 +22,9 @@ type orderedLogMessage struct {
// Logger is the Sink used to captured log messages for logger verification in
// the unified spec tests.
type Logger struct {
lastOrder int
logQueue chan orderedLogMessage
bufSize int
lastOrder int32
logQueue chan orderedLogMessage
}

func newLogger(olm *observeLogMessages, bufSize int) *Logger {
Expand All @@ -44,11 +46,9 @@ 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 {
if log.lastOrder > int32(log.bufSize) {
return
}

Expand All @@ -64,14 +64,16 @@ func (log *Logger) Info(level int, msg string, args ...interface{}) {
// Send the log message to the "orderedLogMessage" channel for
// validation.
log.logQueue <- orderedLogMessage{
order: log.lastOrder + 1,
order: int(log.lastOrder + 1),
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)
qingyang-hu marked this conversation as resolved.
Show resolved Hide resolved
}

// Error implements the logger.Sink interface's "Error" method for printing log
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