Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more cursor tests #3893

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading