From 6737d3260e4059182e8fe59af64a3549dcb2ecf9 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Mon, 11 Dec 2023 21:25:55 +0400 Subject: [PATCH] Clean-up tests a bit (#3835) --- cmd/envtool/tests_test.go | 2 +- integration/cursors/batch_test.go | 9 ++----- integration/cursors/getmore_test.go | 24 ++++++------------- integration/cursors/kill_test.go | 2 +- integration/cursors/tailable_test.go | 4 ++-- .../iterator/testiterator/testiterator.go | 7 ++++++ 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/cmd/envtool/tests_test.go b/cmd/envtool/tests_test.go index 3b61ce642254..cee5927cb269 100644 --- a/cmd/envtool/tests_test.go +++ b/cmd/envtool/tests_test.go @@ -228,7 +228,7 @@ func TestShardTestFuncs(t *testing.T) { testFuncs, err := listTestFuncs(filepath.Join("..", "..", "integration")) require.NoError(t, err) assert.Contains(t, testFuncs, "TestQueryCompatLimit") - assert.Contains(t, testFuncs, "TestGetMoreCommand") + assert.Contains(t, testFuncs, "TestCursorsGetMoreCommand") t.Run("InvalidIndex", func(t *testing.T) { t.Parallel() diff --git a/integration/cursors/batch_test.go b/integration/cursors/batch_test.go index 5e958abf9e8f..129c540550e1 100644 --- a/integration/cursors/batch_test.go +++ b/integration/cursors/batch_test.go @@ -27,7 +27,7 @@ import ( "github.com/FerretDB/FerretDB/integration/setup" ) -func TestBatchSize(t *testing.T) { +func TestCursorsBatchSize(t *testing.T) { t.Parallel() ctx, collection := setup.Setup(t) @@ -158,7 +158,7 @@ func TestBatchSize(t *testing.T) { } } -func TestSingleBatch(t *testing.T) { +func TestCursorsSingleBatch(t *testing.T) { t.Parallel() ctx, collection := setup.Setup(t) @@ -173,7 +173,6 @@ func TestSingleBatch(t *testing.T) { cursorClosed bool // optional, set true for expecting cursor to be closed err *mongo.CommandError // optional, expected error from MongoDB altMessage string // optional, alternative error message for FerretDB, ignored if empty - skip string // optional, skip test with a specified reason }{ "True": { singleBatch: true, @@ -198,10 +197,6 @@ func TestSingleBatch(t *testing.T) { } { name, tc := name, tc t.Run(name, func(t *testing.T) { - if tc.skip != "" { - t.Skip(tc.skip) - } - t.Parallel() var rest bson.D diff --git a/integration/cursors/getmore_test.go b/integration/cursors/getmore_test.go index 30c99ab586f5..b5f9f0a48760 100644 --- a/integration/cursors/getmore_test.go +++ b/integration/cursors/getmore_test.go @@ -33,7 +33,7 @@ import ( "github.com/FerretDB/FerretDB/internal/util/must" ) -func TestGetMoreCommand(t *testing.T) { +func TestCursorsGetMoreCommand(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections // options are applied to create a client that uses single connection pool @@ -64,7 +64,6 @@ func TestGetMoreCommand(t *testing.T) { nextBatch []*types.Document // optional, expected getMore nextBatch err *mongo.CommandError // optional, expected error from MongoDB altMessage string // optional, alternative error message for FerretDB, ignored if empty - skip string // optional, skip test with a specified reason }{ "Int": { firstBatchSize: 1, @@ -243,8 +242,8 @@ func TestGetMoreCommand(t *testing.T) { err: &mongo.CommandError{ Code: 13, Name: "Unauthorized", - Message: "Requested getMore on namespace 'TestGetMoreCommand.invalid'," + - " but cursor belongs to a different namespace TestGetMoreCommand.TestGetMoreCommand", + Message: "Requested getMore on namespace 'TestCursorsGetMoreCommand.invalid'," + + " but cursor belongs to a different namespace TestCursorsGetMoreCommand.TestCursorsGetMoreCommand", }, }, "EmptyCollectionName": { @@ -300,10 +299,6 @@ func TestGetMoreCommand(t *testing.T) { } { name, tc := name, tc t.Run(name, func(t *testing.T) { - if tc.skip != "" { - t.Skip(tc.skip) - } - // Do not run subtests in t.Parallel() to eliminate the occurrence // of session error. // Supporting session would help us understand fix it @@ -440,7 +435,7 @@ func TestGetMoreCommand(t *testing.T) { } } -func TestGetMoreBatchSizeCursor(t *testing.T) { +func TestCursorsGetMoreBatchSizeCursor(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections ctx, collection := setup.Setup(t) @@ -584,7 +579,7 @@ func TestGetMoreBatchSizeCursor(t *testing.T) { }) } -func TestGetMoreCommandConnection(t *testing.T) { +func TestCursorsGetMoreCommandConnection(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections // options are applied to create a client that uses single connection pool @@ -697,7 +692,7 @@ func TestGetMoreCommandConnection(t *testing.T) { }) } -func TestGetMoreCommandMaxTimeMSErrors(t *testing.T) { +func TestCursorsGetMoreCommandMaxTimeMSErrors(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections ctx, collection := setup.Setup(t) @@ -707,7 +702,6 @@ func TestGetMoreCommandMaxTimeMSErrors(t *testing.T) { err *mongo.CommandError // required, expected error from MongoDB altMessage string // optional, alternative error message for FerretDB, ignored if empty - skip string // optional, skip test with a specified reason }{ "NegativeLong": { command: bson.D{ @@ -863,10 +857,6 @@ func TestGetMoreCommandMaxTimeMSErrors(t *testing.T) { } { name, tc := name, tc t.Run(name, func(t *testing.T) { - if tc.skip != "" { - t.Skip(tc.skip) - } - t.Parallel() require.NotNil(t, tc.err, "err must not be nil") @@ -879,7 +869,7 @@ func TestGetMoreCommandMaxTimeMSErrors(t *testing.T) { } } -func TestGetMoreCommandMaxTimeMSCursor(t *testing.T) { +func TestCursorsGetMoreCommandMaxTimeMSCursor(t *testing.T) { // do not run tests in parallel to avoid using too many backend connections // options are applied to create a client that uses single connection pool diff --git a/integration/cursors/kill_test.go b/integration/cursors/kill_test.go index a260da7b254f..59ab731155a6 100644 --- a/integration/cursors/kill_test.go +++ b/integration/cursors/kill_test.go @@ -29,7 +29,7 @@ import ( "github.com/FerretDB/FerretDB/internal/util/testutil" ) -func TestKill(t *testing.T) { +func TestCursorsKill(t *testing.T) { t.Parallel() ctx, collection := setup.Setup(t, shareddata.Strings) diff --git a/integration/cursors/tailable_test.go b/integration/cursors/tailable_test.go index a110813e5933..9a4318f63bcd 100644 --- a/integration/cursors/tailable_test.go +++ b/integration/cursors/tailable_test.go @@ -27,7 +27,7 @@ import ( "github.com/FerretDB/FerretDB/integration/shareddata" ) -func TestTailable(t *testing.T) { +func TestCursorsTailable(t *testing.T) { t.Parallel() t.Run("NonCapped", func(t *testing.T) { @@ -41,7 +41,7 @@ func TestTailable(t *testing.T) { Code: 2, Name: "BadValue", Message: "error processing query: " + - "ns=TestTailable-NonCapped.TestTailable-NonCappedTree: $and\nSort: {}\nProj: {}\n " + + "ns=TestCursorsTailable-NonCapped.TestCursorsTailable-NonCappedTree: $and\nSort: {}\nProj: {}\n " + "tailable cursor requested on non capped collection", } integration.AssertEqualAltCommandError(t, expected, "tailable cursor requested on non capped collection", err) diff --git a/internal/util/iterator/testiterator/testiterator.go b/internal/util/iterator/testiterator/testiterator.go index ed4fab395110..c2efe4f43c7f 100644 --- a/internal/util/iterator/testiterator/testiterator.go +++ b/internal/util/iterator/testiterator/testiterator.go @@ -20,6 +20,8 @@ package testiterator import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/FerretDB/FerretDB/internal/util/iterator" "github.com/FerretDB/FerretDB/internal/util/testutil/teststress" ) @@ -42,5 +44,10 @@ func TestIterator[K, V any](t *testing.T, newIter func() iterator.Interface[K, V iter.Close() }) + + assert.NotPanics(t, func() { + _, _, err := iter.Next() + assert.ErrorIs(t, err, iterator.ErrIteratorDone) + }) }) }