Skip to content

Commit

Permalink
Add more cursor tests (#3893)
Browse files Browse the repository at this point in the history
Closes #3739.
  • Loading branch information
noisersup authored Dec 21, 2023
1 parent cc2fb19 commit b9eafc5
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions integration/cursors/getmore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cursors

import (
"errors"
"fmt"
"math"
"net/url"
"testing"
Expand Down Expand Up @@ -829,6 +830,68 @@ func TestCursorsGetMoreCommandMaxTimeMSErrors(t *testing.T) {
}
}

func TestCursorsGetMoreExhausted(t *testing.T) {
s := setup.SetupWithOpts(t, nil)

collection := s.Collection
db, ctx := collection.Database(), s.Ctx

arr, _ := integration.GenerateDocuments(0, 10)

_, err := collection.InsertMany(ctx, arr)
require.NoError(t, err)

var res bson.D
err = db.RunCommand(ctx, bson.D{
{"find", collection.Name()},
{"batchSize", 1},
}).Decode(&res)

require.NoError(t, err)

firstBatch, cursorID := getFirstBatch(t, res)
require.Equal(t, 1, firstBatch.Len())
require.NotNil(t, cursorID)

err = db.RunCommand(ctx, bson.D{
{"getMore", cursorID},
{"collection", collection.Name()},
{"batchSize", 9},
}).Decode(&res)

require.NoError(t, err)

nextBatch, nextID := getNextBatch(t, res)
require.Equal(t, 9, nextBatch.Len())
assert.Equal(t, cursorID, nextID)

err = db.RunCommand(ctx, bson.D{
{"getMore", cursorID},
{"collection", collection.Name()},
{"batchSize", 1},
}).Decode(&res)

require.NoError(t, err)

nextBatch, nextID = getNextBatch(t, res)
require.Equal(t, 0, nextBatch.Len())
assert.Equal(t, int64(0), nextID)

err = db.RunCommand(ctx, bson.D{
{"getMore", cursorID},
{"collection", collection.Name()},
{"batchSize", 1},
}).Err()

expectedErr := mongo.CommandError{
Code: 43,
Name: "CursorNotFound",
Message: fmt.Sprintf("cursor id %d not found", cursorID),
}

integration.AssertEqualCommandError(t, expectedErr, err)
}

func TestCursorsGetMoreCommandMaxTimeMSCursor(t *testing.T) {
// do not run tests in parallel to avoid using too many backend connections

Expand Down

0 comments on commit b9eafc5

Please sign in to comment.