Skip to content

Commit 9c0cdd5

Browse files
GODRIVER-3659 Add awaitMinPoolSize to clientEntity constructor (#2196)
Co-authored-by: Matt Dale <[email protected]>
1 parent 358b8b3 commit 9c0cdd5

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

internal/integration/unified/client_entity.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ type clientEntity struct {
7575
logQueue chan orderedLogMessage
7676
}
7777

78+
// awaitMinimumPoolSize waits for the client's connection pool to reach the
79+
// specified minimum size. This is a best effort operation that times out after
80+
// some predefined amount of time to avoid blocking tests indefinitely.
81+
func awaitMinimumPoolSize(ctx context.Context, entity *clientEntity, minPoolSize uint64) error {
82+
// Don't spend longer than 500ms awaiting minPoolSize.
83+
awaitCtx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
84+
defer cancel()
85+
86+
ticker := time.NewTicker(100 * time.Millisecond)
87+
defer ticker.Stop()
88+
89+
for {
90+
select {
91+
case <-awaitCtx.Done():
92+
return fmt.Errorf("timed out waiting for client to reach minPoolSize")
93+
case <-ticker.C:
94+
if uint64(entity.eventsCount[connectionReadyEvent]) >= minPoolSize {
95+
return nil
96+
}
97+
}
98+
}
99+
}
100+
78101
func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOptions) (*clientEntity, error) {
79102
// The "configureFailPoint" command should always be ignored.
80103
ignoredCommands := map[string]struct{}{
@@ -203,6 +226,12 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp
203226
return nil, fmt.Errorf("error creating mongo.Client: %w", err)
204227
}
205228

229+
if entityOptions.AwaitMinPoolSize && clientOpts.MinPoolSize != nil && *clientOpts.MinPoolSize > 0 {
230+
if err := awaitMinimumPoolSize(ctx, entity, *clientOpts.MinPoolSize); err != nil {
231+
return nil, err
232+
}
233+
}
234+
206235
entity.Client = client
207236
return entity, nil
208237
}

internal/integration/unified/entity.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ type entityOptions struct {
8282
DatabaseID string `bson:"database"`
8383

8484
ClientEncryptionOpts *clientEncryptionOpts `bson:"clientEncryptionOpts"`
85+
86+
// If true, the unified spec runner must wait for the connection pool to be
87+
// populated for all servers according to the minPoolSize option. If false,
88+
// not specified, or if minPoolSize equals 0, there is no need to wait for any
89+
// specific pool state.
90+
AwaitMinPoolSize bool `bson:"awaitMinPoolSize"`
8591
}
8692

8793
func (eo *entityOptions) setHeartbeatFrequencyMS(freq time.Duration) {

internal/integration/unified/schema_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var (
1818
supportedSchemaVersions = map[int]string{
19-
1: "1.22",
19+
1: "1.26",
2020
}
2121
)
2222

0 commit comments

Comments
 (0)