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

Clean-up tests a bit #3835

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/envtool/tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 2 additions & 7 deletions integration/cursors/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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
Expand Down
24 changes: 7 additions & 17 deletions integration/cursors/getmore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration/cursors/kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions integration/cursors/tailable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions internal/util/iterator/testiterator/testiterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
})
})
}
Loading