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 1 commit
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
noisersup committed Dec 20, 2023
commit 18032aeeb4535e1ab2df1af36ed1a8e98ccce480
45 changes: 27 additions & 18 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 @@ -830,36 +831,29 @@ func TestCursorsGetMoreCommandMaxTimeMSErrors(t *testing.T) {
}

func TestCursorsGetMoreExhausted(t *testing.T) {
s := setup.SetupWithOpts(t, &setup.SetupOpts{
ExtraOptions: url.Values{
"minPoolSize": []string{"1"},
"maxPoolSize": []string{"1"},
"maxIdleTimeMS": []string{"0"},
},
Providers: []shareddata.Provider{shareddata.Composites},
})
s := setup.SetupWithOpts(t, nil)

ctx, collection := s.Ctx, s.Collection
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 = collection.Database().RunCommand(ctx, bson.D{
err = db.RunCommand(ctx, bson.D{
{"find", collection.Name()},
{"batchSize", 1},
{"tailable", true},
}).Decode(&res)

require.NoError(t, err)

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

err = collection.Database().RunCommand(ctx, bson.D{
err = db.RunCommand(ctx, bson.D{
{"getMore", cursorID},
{"collection", collection.Name()},
{"batchSize", 9},
Expand All @@ -869,9 +863,9 @@ func TestCursorsGetMoreExhausted(t *testing.T) {

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

err = collection.Database().RunCommand(ctx, bson.D{
err = db.RunCommand(ctx, bson.D{
{"getMore", cursorID},
{"collection", collection.Name()},
{"batchSize", 1},
Expand All @@ -881,7 +875,21 @@ func TestCursorsGetMoreExhausted(t *testing.T) {

nextBatch, nextID = getNextBatch(t, res)
require.Equal(t, 0, nextBatch.Len())
assert.Equal(t, 0, nextID)
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) {
Expand Down Expand Up @@ -1070,8 +1078,9 @@ func TestCursors(t *testing.T) {

s := setup.SetupWithOpts(t, &setup.SetupOpts{
ExtraOptions: url.Values{
"minPoolSize": []string{"1"},
"maxPoolSize": []string{"1"},
"minPoolSize": []string{"1"},
"maxPoolSize": []string{"1"},
"maxIdleTimeMS": []string{"0"},
},
})

Expand Down
Loading