From c4611be17a74b1d429a9fd0ca1a8817e1a68984e Mon Sep 17 00:00:00 2001 From: noisersup Date: Wed, 20 Dec 2023 16:16:33 +0100 Subject: [PATCH 1/4] wip --- integration/cursors/getmore_test.go | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/integration/cursors/getmore_test.go b/integration/cursors/getmore_test.go index 8f69c99fad3e..e764e24102eb 100644 --- a/integration/cursors/getmore_test.go +++ b/integration/cursors/getmore_test.go @@ -829,6 +829,62 @@ 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}, + }) + + ctx, collection := s.Ctx, s.Collection + + // need large amount of documents for time out to trigger + 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{ + {"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.NotNil(t, cursorID) + + err = collection.Database().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, 0, nextID) + + err = collection.Database().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, 0, nextID) +} + func TestCursorsGetMoreCommandMaxTimeMSCursor(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections From c5c430c2e0c0c765640dd12ab563c4e0eb9e9a17 Mon Sep 17 00:00:00 2001 From: noisersup Date: Wed, 20 Dec 2023 22:55:04 +0100 Subject: [PATCH 2/4] wip --- integration/cursors/getmore_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integration/cursors/getmore_test.go b/integration/cursors/getmore_test.go index e764e24102eb..7d15e6640b10 100644 --- a/integration/cursors/getmore_test.go +++ b/integration/cursors/getmore_test.go @@ -841,7 +841,6 @@ func TestCursorsGetMoreExhausted(t *testing.T) { ctx, collection := s.Ctx, s.Collection - // need large amount of documents for time out to trigger arr, _ := integration.GenerateDocuments(0, 10) _, err := collection.InsertMany(ctx, arr) From 18032aeeb4535e1ab2df1af36ed1a8e98ccce480 Mon Sep 17 00:00:00 2001 From: noisersup Date: Wed, 20 Dec 2023 23:18:01 +0100 Subject: [PATCH 3/4] wip --- integration/cursors/getmore_test.go | 45 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/integration/cursors/getmore_test.go b/integration/cursors/getmore_test.go index 7d15e6640b10..817795fd1f5b 100644 --- a/integration/cursors/getmore_test.go +++ b/integration/cursors/getmore_test.go @@ -16,6 +16,7 @@ package cursors import ( "errors" + "fmt" "math" "net/url" "testing" @@ -830,16 +831,10 @@ 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) @@ -847,19 +842,18 @@ func TestCursorsGetMoreExhausted(t *testing.T) { 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}, @@ -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}, @@ -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) { @@ -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"}, }, }) From 75426f97d2a905c97f3174de3419dea3531dbfc4 Mon Sep 17 00:00:00 2001 From: noisersup Date: Thu, 21 Dec 2023 12:30:41 +0100 Subject: [PATCH 4/4] wip --- integration/cursors/getmore_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/integration/cursors/getmore_test.go b/integration/cursors/getmore_test.go index 817795fd1f5b..1ab4e2b68959 100644 --- a/integration/cursors/getmore_test.go +++ b/integration/cursors/getmore_test.go @@ -1078,9 +1078,8 @@ func TestCursors(t *testing.T) { s := setup.SetupWithOpts(t, &setup.SetupOpts{ ExtraOptions: url.Values{ - "minPoolSize": []string{"1"}, - "maxPoolSize": []string{"1"}, - "maxIdleTimeMS": []string{"0"}, + "minPoolSize": []string{"1"}, + "maxPoolSize": []string{"1"}, }, })