@@ -8,24 +8,17 @@ package integration
8
8
9
9
import (
10
10
"context"
11
- "fmt"
12
- "os"
13
11
"strings"
14
12
"testing"
15
- "time"
16
13
17
14
"github.com/mongodb/mongo-go-driver/bson"
18
15
"github.com/mongodb/mongo-go-driver/internal/testutil"
19
- "github.com/mongodb/mongo-go-driver/internal/testutil/israce"
20
16
"github.com/mongodb/mongo-go-driver/mongo/writeconcern"
21
17
"github.com/mongodb/mongo-go-driver/x/bsonx"
22
- "github.com/mongodb/mongo-go-driver/x/bsonx/bsoncore"
23
- "github.com/mongodb/mongo-go-driver/x/mongo/driver"
24
18
"github.com/mongodb/mongo-go-driver/x/mongo/driver/topology"
25
19
"github.com/mongodb/mongo-go-driver/x/network/address"
26
20
"github.com/mongodb/mongo-go-driver/x/network/command"
27
21
"github.com/mongodb/mongo-go-driver/x/network/description"
28
- "github.com/stretchr/testify/assert"
29
22
)
30
23
31
24
func TestCommandAggregate (t * testing.T ) {
@@ -158,146 +151,3 @@ func TestCommandAggregate(t *testing.T) {
158
151
noerr (t , err )
159
152
})
160
153
}
161
-
162
- func TestAggregatePassesMaxAwaitTimeMSThroughToGetMore (t * testing.T ) {
163
- if os .Getenv ("TOPOLOGY" ) != "replica_set" {
164
- t .Skip ()
165
- }
166
-
167
- startedChan , succeededChan , failedChan , monitor := initMonitor ()
168
-
169
- dbName := fmt .Sprintf ("mongo-go-driver-%d-agg" , os .Getpid ())
170
- colName := testutil .ColName (t )
171
-
172
- server , err := testutil .MonitoredTopology (t , dbName , monitor ).SelectServer (context .Background (), description .WriteSelector ())
173
- noerr (t , err )
174
-
175
- versionCmd := bsonx.Doc {{"serverStatus" , bsonx .Int32 (1 )}}
176
- serverStatus , err := testutil .RunCommand (t , server .Server , dbName , versionCmd )
177
- version , err := serverStatus .LookupErr ("version" )
178
-
179
- if compareVersions (t , version .StringValue (), "3.6" ) < 0 {
180
- t .Skip ()
181
- }
182
-
183
- // create capped collection
184
- createCmd := bsonx.Doc {
185
- {"create" , bsonx .String (colName )},
186
- {"capped" , bsonx .Boolean (true )},
187
- {"size" , bsonx .Int32 (1000 )}}
188
- _ , err = testutil .RunCommand (t , server .Server , dbName , createCmd )
189
- noerr (t , err )
190
-
191
- conn , err := server .Connection (context .Background ())
192
- noerr (t , err )
193
-
194
- // create an aggregate command that results with a TAILABLEAWAIT cursor
195
- result , err := (& command.Aggregate {
196
- NS : command.Namespace {DB : dbName , Collection : testutil .ColName (t )},
197
- Pipeline : bsonx.Arr {
198
- bsonx .Document (bsonx.Doc {
199
- {"$changeStream" , bsonx .Document (bsonx.Doc {})}}),
200
- bsonx .Document (bsonx.Doc {
201
- {"$match" , bsonx .Document (bsonx.Doc {
202
- {"fullDocument._id" , bsonx .Document (bsonx.Doc {{"$gte" , bsonx .Int32 (1 )}})},
203
- })}})},
204
- Opts : []bsonx.Elem {{"batchSize" , bsonx .Int32 (2 )}},
205
- CursorOpts : []bsonx.Elem {
206
- {"batchSize" , bsonx .Int32 (2 )},
207
- {"maxTimeMS" , bsonx .Int64 (50 )},
208
- },
209
- }).RoundTrip (context .Background (), server .SelectedDescription (), conn )
210
- noerr (t , err )
211
-
212
- cursor , err := driver .NewBatchCursor (
213
- bsoncore .Document (result ), nil , nil , server .Server ,
214
- bsonx.Elem {"batchSize" , bsonx .Int32 (2 )}, bsonx.Elem {"maxTimeMS" , bsonx .Int64 (50 )},
215
- )
216
- noerr (t , err )
217
-
218
- // insert some documents
219
- insertCmd := bsonx.Doc {
220
- {"insert" , bsonx .String (colName )},
221
- {"documents" , bsonx .Array (bsonx.Arr {
222
- bsonx .Document (bsonx.Doc {{"_id" , bsonx .Int32 (1 )}}),
223
- bsonx .Document (bsonx.Doc {{"_id" , bsonx .Int32 (2 )}}),
224
- bsonx .Document (bsonx.Doc {{"_id" , bsonx .Int32 (3 )}})})}}
225
- _ , err = testutil .RunCommand (t , server .Server , dbName , insertCmd )
226
-
227
- // wait a bit between insert and getMore commands
228
- time .Sleep (time .Millisecond * 100 )
229
- if israce .Enabled {
230
- time .Sleep (time .Millisecond * 400 ) // wait a little longer when race detector is enabled.
231
- }
232
-
233
- ctx , cancel := context .WithCancel (context .Background ())
234
- if israce .Enabled {
235
- time .AfterFunc (time .Millisecond * 2000 , cancel )
236
- } else {
237
- time .AfterFunc (time .Millisecond * 900 , cancel )
238
- }
239
- for cursor .Next (ctx ) {
240
- }
241
-
242
- // allow for iteration over range chan
243
- close (startedChan )
244
- close (succeededChan )
245
- close (failedChan )
246
-
247
- // no commands should have failed
248
- if len (failedChan ) != 0 {
249
- t .Errorf ("%d command(s) failed" , len (failedChan ))
250
- }
251
-
252
- // check the expected commands were started
253
- for started := range startedChan {
254
- switch started .CommandName {
255
- case "aggregate" :
256
- assert .Equal (t , 2 , int (started .Command .Lookup ("cursor" , "batchSize" ).Int32 ()))
257
- assert .Equal (t , started .Command .Lookup ("maxAwaitTimeMS" ), bson.RawValue {},
258
- "Should not have sent maxAwaitTimeMS in find command" )
259
- case "getMore" :
260
- assert .Equal (t , 2 , int (started .Command .Lookup ("batchSize" ).Int32 ()))
261
- assert .Equal (t , 50 , int (started .Command .Lookup ("maxTimeMS" ).Int64 ()),
262
- "Should have sent maxTimeMS in getMore command" )
263
- default :
264
- continue
265
- }
266
- }
267
-
268
- // to keep track of seen documents
269
- id := 1
270
-
271
- // check expected commands succeeded
272
- for succeeded := range succeededChan {
273
- switch succeeded .CommandName {
274
- case "aggregate" :
275
- assert .Equal (t , 1 , int (succeeded .Reply .Lookup ("ok" ).Double ()))
276
-
277
- actual , err := succeeded .Reply .Lookup ("cursor" , "firstBatch" ).Array ().Values ()
278
- assert .NoError (t , err )
279
-
280
- for _ , v := range actual {
281
- assert .Equal (t , id , int (v .Document ().Lookup ("fullDocument" , "_id" ).Int32 ()))
282
- id ++
283
- }
284
- case "getMore" :
285
- assert .Equal (t , "getMore" , succeeded .CommandName )
286
- assert .Equal (t , 1 , int (succeeded .Reply .Lookup ("ok" ).Double ()))
287
-
288
- actual , err := succeeded .Reply .Lookup ("cursor" , "nextBatch" ).Array ().Values ()
289
- assert .NoError (t , err )
290
-
291
- for _ , v := range actual {
292
- assert .Equal (t , id , int (v .Document ().Lookup ("fullDocument" , "_id" ).Int32 ()))
293
- id ++
294
- }
295
- default :
296
- continue
297
- }
298
- }
299
-
300
- if id <= 3 {
301
- t .Errorf ("not all documents returned; last seen id = %d" , id - 1 )
302
- }
303
- }
0 commit comments