Skip to content

Commit fee155a

Browse files
GODRIVER-3444 Use prose tests
1 parent cec268a commit fee155a

File tree

4 files changed

+86
-22
lines changed

4 files changed

+86
-22
lines changed

internal/integration/cursor_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go.mongodb.org/mongo-driver/v2/internal/assert"
1818
"go.mongodb.org/mongo-driver/v2/internal/failpoint"
1919
"go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
20+
"go.mongodb.org/mongo-driver/v2/internal/require"
2021
"go.mongodb.org/mongo-driver/v2/mongo"
2122
"go.mongodb.org/mongo-driver/v2/mongo/options"
2223
)
@@ -303,6 +304,75 @@ func TestCursor(t *testing.T) {
303304
batchSize = sizeVal.Int32()
304305
assert.Equal(mt, int32(4), batchSize, "expected batchSize 4, got %v", batchSize)
305306
})
307+
308+
tailableAwaitDataCursorOpts := mtest.NewOptions().MinServerVersion("4.4").
309+
Topologies(mtest.ReplicaSet, mtest.Sharded, mtest.LoadBalanced, mtest.Single)
310+
311+
mt.RunOpts("tailable awaitData cursor", tailableAwaitDataCursorOpts, func(mt *mtest.T) {
312+
mt.Run("apply remaining timeoutMS if less than maxAwaitTimeMS", func(mt *mtest.T) {
313+
initCollection(mt, mt.Coll)
314+
mt.ClearEvents()
315+
316+
// Create a find cursor
317+
opts := options.Find().SetBatchSize(1).SetMaxAwaitTime(100 * time.Millisecond)
318+
319+
cursor, err := mt.Coll.Find(context.Background(), bson.D{}, opts)
320+
require.NoError(mt, err)
321+
322+
_ = mt.GetStartedEvent() // Empty find from started list.
323+
324+
defer cursor.Close(context.Background())
325+
326+
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
327+
defer cancel()
328+
329+
// Iterate twice to force a getMore
330+
cursor.Next(ctx)
331+
cursor.Next(ctx)
332+
333+
cmd := mt.GetStartedEvent().Command
334+
335+
maxTimeMSRaw, err := cmd.LookupErr("maxTimeMS")
336+
require.NoError(mt, err)
337+
338+
got, ok := maxTimeMSRaw.AsInt64OK()
339+
require.True(mt, ok)
340+
341+
assert.LessOrEqual(mt, got, int64(50))
342+
})
343+
344+
mt.RunOpts("apply maxAwaitTimeMS if less than remaining timeout", tailableAwaitDataCursorOpts, func(mt *mtest.T) {
345+
initCollection(mt, mt.Coll)
346+
mt.ClearEvents()
347+
348+
// Create a find cursor
349+
opts := options.Find().SetBatchSize(1).SetMaxAwaitTime(50 * time.Millisecond)
350+
351+
cursor, err := mt.Coll.Find(context.Background(), bson.D{}, opts)
352+
require.NoError(mt, err)
353+
354+
_ = mt.GetStartedEvent() // Empty find from started list.
355+
356+
defer cursor.Close(context.Background())
357+
358+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
359+
defer cancel()
360+
361+
// Iterate twice to force a getMore
362+
cursor.Next(ctx)
363+
cursor.Next(ctx)
364+
365+
cmd := mt.GetStartedEvent().Command
366+
367+
maxTimeMSRaw, err := cmd.LookupErr("maxTimeMS")
368+
require.NoError(mt, err)
369+
370+
got, ok := maxTimeMSRaw.AsInt64OK()
371+
require.True(mt, ok)
372+
373+
assert.LessOrEqual(mt, got, int64(50))
374+
})
375+
})
306376
}
307377

308378
type tryNextCursor interface {

internal/integration/unified/unified_spec_runner.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ var (
9292
// timeoutMS.
9393
//
9494
// Once GODRIVER-3473 is completed, we can continue running these tests.
95-
"error if maxAwaitTimeMS is equal to timeoutMS": "Go Driver does not implement this behavior. See GODRIVER-3473",
96-
"error if maxAwaitTimeMS is greater than timeoutMS": "Go Driver does not implement this behavior. See GODRIVER-3473",
95+
"error if maxAwaitTimeMS is equal to timeoutMS": "Go Driver does not implement this behavior. See GODRIVER-3473",
96+
"error if maxAwaitTimeMS is greater than timeoutMS": "Go Driver does not implement this behavior. See GODRIVER-3473",
97+
"apply remaining timeoutMS if less than maxAwaitTimeMS": "Go Driver does not implement this behavior. See GODRIVER-3473",
98+
"apply maxAwaitTimeMS if less than remaining timeout": "Go Driver does not implement this behavior. See GODRIVER-3473",
9799

98100
// DRIVERS-2953: This test requires that the driver sends a "getMore"
99101
// with "maxTimeMS" set. However, "getMore" can only include "maxTimeMS"

testdata/client-side-operations-timeout/tailable-awaitData.json

+9-15
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
]
421421
},
422422
{
423-
"description": "apply remaining timeoutMS if less than maxAwaitTimeMS ",
423+
"description": "apply remaining timeoutMS if less than maxAwaitTimeMS",
424424
"operations": [
425425
{
426426
"name": "createFindCursor",
@@ -429,23 +429,20 @@
429429
"filter": {},
430430
"cursorType": "tailableAwait",
431431
"batchSize": 1,
432-
"maxAwaitTimeMS": 100
432+
"maxAwaitTimeMS": 100,
433+
"timeoutMS": 50
433434
},
434435
"saveResultAsEntity": "tailableCursor"
435436
},
436437
{
437438
"name": "iterateOnce",
438439
"object": "tailableCursor",
439-
"arguments": {
440-
"timeoutMS": 50
441-
}
440+
"arguments": null
442441
},
443442
{
444443
"name": "iterateOnce",
445444
"object": "tailableCursor",
446-
"arguments": {
447-
"timeoutMS": 50
448-
}
445+
"arguments": null
449446
}
450447
],
451448
"expectEvents": [
@@ -483,23 +480,20 @@
483480
"filter": {},
484481
"cursorType": "tailableAwait",
485482
"batchSize": 1,
486-
"maxAwaitTimeMS": 50
483+
"maxAwaitTimeMS": 50,
484+
"timeoutMS": 100
487485
},
488486
"saveResultAsEntity": "tailableCursor"
489487
},
490488
{
491489
"name": "iterateOnce",
492490
"object": "tailableCursor",
493-
"arguments": {
494-
"timeoutMS": 100
495-
}
491+
"arguments": null
496492
},
497493
{
498494
"name": "iterateOnce",
499495
"object": "tailableCursor",
500-
"arguments": {
501-
"timeoutMS": 100
502-
}
496+
"arguments": null
503497
}
504498
],
505499
"expectEvents": [

testdata/client-side-operations-timeout/tailable-awaitData.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ tests:
247247
getMore: { $$type: ["int", "long"] }
248248
collection: *collectionName
249249

250-
- description: "apply remaining timeoutMS if less than maxAwaitTimeMS "
250+
- description: "apply remaining timeoutMS if less than maxAwaitTimeMS"
251251
operations:
252252
- name: createFindCursor
253253
object: *collection
@@ -256,16 +256,15 @@ tests:
256256
cursorType: tailableAwait
257257
batchSize: 1
258258
maxAwaitTimeMS: 100
259+
timeoutMS: 50
259260
saveResultAsEntity: &tailableCursor tailableCursor
260261
# Iterate twice to force a getMore.
261262
- name: iterateOnce
262263
object: *tailableCursor
263264
arguments:
264-
timeoutMS: 50
265265
- name: iterateOnce
266266
object: *tailableCursor
267267
arguments:
268-
timeoutMS: 50
269268
expectEvents:
270269
- client: *client
271270
events:
@@ -287,16 +286,15 @@ tests:
287286
cursorType: tailableAwait
288287
batchSize: 1
289288
maxAwaitTimeMS: 50
289+
timeoutMS: 100
290290
saveResultAsEntity: &tailableCursor tailableCursor
291291
# Iterate twice to force a getMore.
292292
- name: iterateOnce
293293
object: *tailableCursor
294294
arguments:
295-
timeoutMS: 100
296295
- name: iterateOnce
297296
object: *tailableCursor
298297
arguments:
299-
timeoutMS: 100
300298
expectEvents:
301299
- client: *client
302300
events:

0 commit comments

Comments
 (0)