Skip to content

Commit 0d4da18

Browse files
GODRIVER-3473 Cleanup
1 parent 9eea702 commit 0d4da18

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

internal/mongoutil/mongoutil_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"go.mongodb.org/mongo-driver/v2/internal/assert"
16+
"go.mongodb.org/mongo-driver/v2/internal/ptrutil"
1617
"go.mongodb.org/mongo-driver/v2/mongo/options"
1718
)
1819

@@ -37,12 +38,6 @@ func BenchmarkNewOptions(b *testing.B) {
3738
}
3839

3940
func TestValidChangeStreamTimeouts(t *testing.T) {
40-
t.Parallel()
41-
42-
newDurPtr := func(dur time.Duration) *time.Duration {
43-
return &dur
44-
}
45-
4641
tests := []struct {
4742
name string
4843
parent context.Context
@@ -61,7 +56,7 @@ func TestValidChangeStreamTimeouts(t *testing.T) {
6156
{
6257
name: "no context deadline and maxAwaitTimeout",
6358
parent: context.Background(),
64-
maxAwaitTimeout: newDurPtr(1),
59+
maxAwaitTimeout: ptrutil.Ptr(time.Duration(1)),
6560
timeout: nil,
6661
wantTimeout: 0,
6762
want: true,
@@ -70,50 +65,46 @@ func TestValidChangeStreamTimeouts(t *testing.T) {
7065
name: "no context deadline and timeout",
7166
parent: context.Background(),
7267
maxAwaitTimeout: nil,
73-
timeout: newDurPtr(1),
68+
timeout: ptrutil.Ptr(time.Duration(1)),
7469
wantTimeout: 0,
7570
want: true,
7671
},
7772
{
7873
name: "no context deadline and maxAwaitTime gt timeout",
7974
parent: context.Background(),
80-
maxAwaitTimeout: newDurPtr(2),
81-
timeout: newDurPtr(1),
75+
maxAwaitTimeout: ptrutil.Ptr(time.Duration(2)),
76+
timeout: ptrutil.Ptr(time.Duration(1)),
8277
wantTimeout: 0,
8378
want: false,
8479
},
8580
{
8681
name: "no context deadline and maxAwaitTime lt timeout",
8782
parent: context.Background(),
88-
maxAwaitTimeout: newDurPtr(1),
89-
timeout: newDurPtr(2),
83+
maxAwaitTimeout: ptrutil.Ptr(time.Duration(1)),
84+
timeout: ptrutil.Ptr(time.Duration(2)),
9085
wantTimeout: 0,
9186
want: true,
9287
},
9388
{
9489
name: "no context deadline and maxAwaitTime eq timeout",
9590
parent: context.Background(),
96-
maxAwaitTimeout: newDurPtr(1),
97-
timeout: newDurPtr(1),
91+
maxAwaitTimeout: ptrutil.Ptr(time.Duration(1)),
92+
timeout: ptrutil.Ptr(time.Duration(1)),
9893
wantTimeout: 0,
9994
want: false,
10095
},
10196
{
10297
name: "no context deadline and maxAwaitTime with negative timeout",
10398
parent: context.Background(),
104-
maxAwaitTimeout: newDurPtr(1),
105-
timeout: newDurPtr(-1),
99+
maxAwaitTimeout: ptrutil.Ptr(time.Duration(1)),
100+
timeout: ptrutil.Ptr(time.Duration(-1)),
106101
wantTimeout: 0,
107102
want: true,
108103
},
109104
}
110105

111106
for _, test := range tests {
112-
test := test // Capture the range variable
113-
114107
t.Run(test.name, func(t *testing.T) {
115-
t.Parallel()
116-
117108
got := ValidMaxAwaitTimeMS(test.parent, test.timeout, test.maxAwaitTimeout)
118109
assert.Equal(t, test.want, got)
119110
})

internal/spectest/skip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ var skipTests = map[string][]string{
816816
"TestUnifiedSpec/transactions-convenient-api/tests/unified/commit.json/withTransaction_commits_after_callback_returns",
817817
},
818818

819-
"Address CSOT Compliance Issue in for Timeout Handling in Cursor Constructors (GODRIVER-3480)": {
819+
"Address CSOT Compliance Issue in Timeout Handling for Cursor Constructors (GODRIVER-3480)": {
820820
"TestUnifiedSpec/client-side-operations-timeout/tests/tailable-awaitData.json/apply_remaining_timeoutMS_if_less_than_maxAwaitTimeMS",
821821
},
822822
}

mongo/change_stream.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ func (cs *ChangeStream) next(ctx context.Context, nonBlocking bool) bool {
673673

674674
func (cs *ChangeStream) loopNext(ctx context.Context, nonBlocking bool) {
675675
// Sending a maxAwaitTimeMS option to the server that is less than or equal to
676-
// the operation timeout will result in a socket timeout error. This block
677-
// short-circuits that behavior.
676+
// the operation timeout will result in a socket timeout error.
678677
if csOpts := cs.options; csOpts != nil && cs.client != nil &&
679678
!mongoutil.ValidMaxAwaitTimeMS(ctx, cs.client.timeout, csOpts.MaxAwaitTime) {
680679
cs.err = fmt.Errorf("MaxAwaitTime must be less than the operation timeout")

mongo/collection.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,7 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption
955955
}
956956

957957
// Sending a maxAwaitTimeMS option to the server that is less than or equal to
958-
// the operation timeout will result in a socket timeout error. This block
959-
// short-circuits that behavior.
958+
// the operation timeout will result in a socket timeout error.
960959
if c := a.client; c != nil && !mongoutil.ValidMaxAwaitTimeMS(a.ctx, c.timeout, args.MaxAwaitTime) {
961960
return nil, fmt.Errorf("MaxAwaitTime must be less than the operation timeout")
962961
}
@@ -1359,8 +1358,7 @@ func (coll *Collection) find(
13591358
}
13601359

13611360
// Sending a maxAwaitTimeMS option to the server that is less than or equal to
1362-
// the operation timeout will result in a socket timeout error. This block
1363-
// short-circuits that behavior.
1361+
// the operation timeout will result in a socket timeout error.
13641362
if c := coll.client; c != nil && !mongoutil.ValidMaxAwaitTimeMS(ctx, c.timeout, args.MaxAwaitTime) {
13651363
return nil, fmt.Errorf("MaxAwaitTime must be less than the operation timeout")
13661364
}

0 commit comments

Comments
 (0)