7
7
package integration
8
8
9
9
import (
10
+ "context"
10
11
"testing"
11
12
12
13
"go.mongodb.org/mongo-driver/bson"
@@ -36,14 +37,14 @@ func TestCausalConsistency_Supported(t *testing.T) {
36
37
37
38
sess , err := mt .Client .StartSession ()
38
39
assert .Nil (mt , err , "StartSession error: %v" , err )
39
- defer sess .EndSession (mtest .Background )
40
+ defer sess .EndSession (context .Background () )
40
41
assert .Nil (mt , sess .OperationTime (), "expected nil operation time, got %v" , sess .OperationTime ())
41
42
})
42
43
mt .Run ("no cluster time on first command" , func (mt * mtest.T ) {
43
44
// first read in a causally consistent session must not send afterClusterTime to the server
44
45
45
46
ccOpts := options .Session ().SetCausalConsistency (true )
46
- _ = mt .Client .UseSessionWithOptions (mtest .Background , ccOpts , func (sc mongo.SessionContext ) error {
47
+ _ = mt .Client .UseSessionWithOptions (context .Background () , ccOpts , func (sc mongo.SessionContext ) error {
47
48
_ , _ = mt .Coll .Find (sc , bson.D {})
48
49
return nil
49
50
})
@@ -57,9 +58,9 @@ func TestCausalConsistency_Supported(t *testing.T) {
57
58
58
59
sess , err := mt .Client .StartSession ()
59
60
assert .Nil (mt , err , "StartSession error: %v" , err )
60
- defer sess .EndSession (mtest .Background )
61
+ defer sess .EndSession (context .Background () )
61
62
62
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
63
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
63
64
_ , _ = mt .Coll .Find (sc , bson.D {})
64
65
return nil
65
66
})
@@ -85,9 +86,9 @@ func TestCausalConsistency_Supported(t *testing.T) {
85
86
mt .Run (sf .name , func (mt * mtest.T ) {
86
87
sess , err := mt .Client .StartSession ()
87
88
assert .Nil (mt , err , "StartSession error: %v" , err )
88
- defer sess .EndSession (mtest .Background )
89
+ defer sess .EndSession (context .Background () )
89
90
90
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
91
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
91
92
_ = mt .Coll .FindOne (sc , bson.D {})
92
93
return nil
93
94
})
@@ -115,14 +116,14 @@ func TestCausalConsistency_Supported(t *testing.T) {
115
116
mt .Run (sf .name , func (mt * mtest.T ) {
116
117
sess , err := mt .Client .StartSession ()
117
118
assert .Nil (mt , err , "StartSession error: %v" , err )
118
- defer sess .EndSession (mtest .Background )
119
+ defer sess .EndSession (context .Background () )
119
120
120
121
_ = sf .execute (mt , sess )
121
122
currOptime := sess .OperationTime ()
122
123
assert .NotNil (mt , currOptime , "expected session operation time, got nil" )
123
124
124
125
mt .ClearEvents ()
125
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
126
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
126
127
_ = mt .Coll .FindOne (sc , bson.D {})
127
128
return nil
128
129
})
@@ -136,7 +137,7 @@ func TestCausalConsistency_Supported(t *testing.T) {
136
137
// a read operation in a non causally-consistent session should not include afterClusterTime
137
138
138
139
sessOpts := options .Session ().SetCausalConsistency (false )
139
- _ = mt .Client .UseSessionWithOptions (mtest .Background , sessOpts , func (sc mongo.SessionContext ) error {
140
+ _ = mt .Client .UseSessionWithOptions (context .Background () , sessOpts , func (sc mongo.SessionContext ) error {
140
141
_ , _ = mt .Coll .Find (sc , bson.D {})
141
142
mt .ClearEvents ()
142
143
_ , _ = mt .Coll .Find (sc , bson.D {})
@@ -152,15 +153,15 @@ func TestCausalConsistency_Supported(t *testing.T) {
152
153
153
154
sess , err := mt .Client .StartSession ()
154
155
assert .Nil (mt , err , "StartSession error: %v" , err )
155
- defer sess .EndSession (mtest .Background )
156
+ defer sess .EndSession (context .Background () )
156
157
157
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
158
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
158
159
_ = mt .Coll .FindOne (sc , bson.D {})
159
160
return nil
160
161
})
161
162
currOptime := sess .OperationTime ()
162
163
mt .ClearEvents ()
163
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
164
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
164
165
_ = mt .Coll .FindOne (sc , bson.D {})
165
166
return nil
166
167
})
@@ -174,15 +175,15 @@ func TestCausalConsistency_Supported(t *testing.T) {
174
175
mt .RunOpts ("custom read concern" , mtest .NewOptions ().ClientOptions (localRcOpts ), func (mt * mtest.T ) {
175
176
sess , err := mt .Client .StartSession ()
176
177
assert .Nil (mt , err , "StartSession error: %v" , err )
177
- defer sess .EndSession (mtest .Background )
178
+ defer sess .EndSession (context .Background () )
178
179
179
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
180
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
180
181
_ = mt .Coll .FindOne (sc , bson.D {})
181
182
return nil
182
183
})
183
184
currOptime := sess .OperationTime ()
184
185
mt .ClearEvents ()
185
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
186
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
186
187
_ = mt .Coll .FindOne (sc , bson.D {})
187
188
return nil
188
189
})
@@ -198,9 +199,9 @@ func TestCausalConsistency_Supported(t *testing.T) {
198
199
199
200
sess , err := mt .Client .StartSession ()
200
201
assert .Nil (mt , err , "StartSession error: %v" , err )
201
- defer sess .EndSession (mtest .Background )
202
+ defer sess .EndSession (context .Background () )
202
203
203
- _ = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
204
+ _ = mongo .WithSession (context .Background () , sess , func (sc mongo.SessionContext ) error {
204
205
_ , _ = mt .Coll .InsertOne (sc , bson.D {{"x" , 1 }})
205
206
return nil
206
207
})
@@ -210,7 +211,7 @@ func TestCausalConsistency_Supported(t *testing.T) {
210
211
mt .Run ("clusterTime included" , func (mt * mtest.T ) {
211
212
// $clusterTime should be included in commands if the deployment supports cluster times
212
213
213
- _ = mt .Coll .FindOne (mtest .Background , bson.D {})
214
+ _ = mt .Coll .FindOne (context .Background () , bson.D {})
214
215
evt := mt .GetStartedEvent ()
215
216
assert .Equal (mt , "find" , evt .CommandName , "expected command 'find', got '%v'" , evt .CommandName )
216
217
_ , err := evt .Command .LookupErr ("$clusterTime" )
@@ -233,7 +234,7 @@ func TestCausalConsistency_NotSupported(t *testing.T) {
233
234
// support cluster times
234
235
235
236
sessOpts := options .Session ().SetCausalConsistency (true )
236
- _ = mt .Client .UseSessionWithOptions (mtest .Background , sessOpts , func (sc mongo.SessionContext ) error {
237
+ _ = mt .Client .UseSessionWithOptions (context .Background () , sessOpts , func (sc mongo.SessionContext ) error {
237
238
_ , _ = mt .Coll .Find (sc , bson.D {})
238
239
return nil
239
240
})
@@ -245,7 +246,7 @@ func TestCausalConsistency_NotSupported(t *testing.T) {
245
246
mt .Run ("clusterTime not included" , func (mt * mtest.T ) {
246
247
// $clusterTime should not be included in commands if the deployment does not support cluster times
247
248
248
- _ = mt .Coll .FindOne (mtest .Background , bson.D {})
249
+ _ = mt .Coll .FindOne (context .Background () , bson.D {})
249
250
evt := mt .GetStartedEvent ()
250
251
assert .Equal (mt , "find" , evt .CommandName , "expected command 'find', got '%v'" , evt .CommandName )
251
252
_ , err := evt .Command .LookupErr ("$clusterTime" )
0 commit comments