Skip to content

Commit

Permalink
Merge branch 'main' into 1432_implement_unset_pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 14, 2023
2 parents 265458f + 89d6562 commit fe5cf9d
Show file tree
Hide file tree
Showing 15 changed files with 1,018 additions and 69 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,17 @@ If tests fail and the output is too confusing, try running them sequentially by

You can also run `task -C 1` to limit the number of concurrent tasks, which is useful for debugging.

To run a single test case, you may want to use the predefined variable `TEST_RUN`.
For example, to run a single test case for in-process FerretDB with `pg` handler you may use `task test-integration-pg TEST_RUN='TestName/TestCaseName'`.

Finally, since all tests just run `go test` with various arguments and flags under the hood,
you may also use all standard `go` tool facilities,
including [`GOFLAGS` environment variable](https://pkg.go.dev/cmd/go#hdr-Environment_variables).
For example:

- to run a single test case for in-process FerretDB with `pg` handler
with all subtests running sequentially,
you may use `env GOFLAGS='-run=TestName/TestCaseName -parallel=1' task test-integration-pg`;
you may use `env GOFLAGS='-parallel=1' task test-integration-pg TEST_RUN='TestName/TestCaseName'`;
- to run all tests for in-process FerretDB with `tigris` handler
with [Go execution tracer](https://pkg.go.dev/runtime/trace) enabled,
you may use `env GOFLAGS='-trace=trace.out' task test-integration-tigris`.
Expand Down
21 changes: 11 additions & 10 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vars:
UNIXSOCKETFLAG: -target-unix-socket={{ne OS "windows"}}
BUILDTAGS: ferretdb_debug,ferretdb_tigris,ferretdb_hana
SERVICES: postgres postgres_secured tigris tigris1 tigris2 tigris3 tigris4 mongodb mongodb_secured jaeger
TEST_RUN: ""

tasks:
# invoked when `task` is run without arguments
Expand Down Expand Up @@ -189,72 +190,72 @@ tasks:
dir: integration
cmds:
- >
go test -count=1 -run='{{.RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
go test -count=1 -run='{{or .TEST_RUN .SHARD_RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-pg.txt .
-target-backend=ferretdb-pg
-target-tls
-postgresql-url=postgres://username@127.0.0.1:5432/ferretdb
-compat-url='mongodb://username:password@127.0.0.1:47018/?tls=true&tlsCertificateKeyFile=../build/certs/client.pem&tlsCaFile=../build/certs/rootCA-cert.pem'
vars:
RUN:
SHARD_RUN:
sh: go run -C .. ./cmd/envtool tests shard --index={{.SHARD_INDEX | default 1}} --total={{.SHARD_TOTAL | default 1}}

test-integration-sqlite:
desc: "Run integration tests for `sqlite` handler"
dir: integration
cmds:
- >
go test -count=1 -run='{{.RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
go test -count=1 -run='{{or .TEST_RUN .SHARD_RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-sqlite.txt .
-target-backend=ferretdb-sqlite
-target-tls
-compat-url='mongodb://username:password@127.0.0.1:47018/?tls=true&tlsCertificateKeyFile=../build/certs/client.pem&tlsCaFile=../build/certs/rootCA-cert.pem'
-disable-filter-pushdown
vars:
RUN:
SHARD_RUN:
sh: go run -C .. ./cmd/envtool tests shard --index={{.SHARD_INDEX | default 1}} --total={{.SHARD_TOTAL | default 1}}

test-integration-tigris:
desc: "Run integration tests for `tigris` handler"
dir: integration
cmds:
- >
go test -count=1 -run='{{.RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
go test -count=1 -run='{{or .TEST_RUN .SHARD_RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-tigris.txt .
-target-backend=ferretdb-tigris
{{.UNIXSOCKETFLAG}}
-tigris-urls=127.0.0.1:8081,127.0.0.1:8091,127.0.0.1:8092,127.0.0.1:8093,127.0.0.1:8094
-compat-url=mongodb://127.0.0.1:47017/
vars:
RUN:
SHARD_RUN:
sh: go run -C .. ./cmd/envtool tests shard --index={{.SHARD_INDEX | default 1}} --total={{.SHARD_TOTAL | default 1}}

test-integration-hana:
desc: "Run integration tests for `hana` handler"
dir: integration
cmds:
- >
go test -count=1 -run='{{.RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
go test -count=1 -run='{{or .TEST_RUN .SHARD_RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-hana.txt .
-target-backend=ferretdb-hana
{{.UNIXSOCKETFLAG}}
-hana-url=$FERRETDB_HANA_URL
-compat-url=mongodb://127.0.0.1:47017/
vars:
RUN:
SHARD_RUN:
sh: go run -C .. ./cmd/envtool tests shard --index={{.SHARD_INDEX | default 1}} --total={{.SHARD_TOTAL | default 1}}

test-integration-mongodb:
desc: "Run integration tests for MongoDB"
dir: integration
cmds:
- >
go test -count=1 -run='{{.RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
go test -count=1 -run='{{or .TEST_RUN .SHARD_RUN}}' -timeout={{.INTEGRATIONTIME}} {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-mongodb.txt .
-target-url=mongodb://127.0.0.1:47017/
-target-backend=mongodb
vars:
RUN:
SHARD_RUN:
sh: go run -C .. ./cmd/envtool tests shard --index={{.SHARD_INDEX | default 1}} --total={{.SHARD_TOTAL | default 1}}

bench-unit-short:
Expand Down
92 changes: 89 additions & 3 deletions integration/aggregate_documents_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func TestAggregateCompatGroup(t *testing.T) {
resultType: emptyResult,
skip: "https://github.com/FerretDB/FerretDB/issues/2123",
},
"IDTypeOperator": {
"IDType": {
pipeline: bson.A{bson.D{{"$group", bson.D{
{"_id", bson.D{{"$type", "_id"}}},
}}}},
Expand Down Expand Up @@ -1597,12 +1597,98 @@ func TestAggregateCompatProject(t *testing.T) {
},
resultType: emptyResult,
},
"TypeOperator": {
"Type": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", "$v"}}}}}},
},
skip: "https://github.com/FerretDB/FerretDB/issues/2679",
},
"TypeNonExistent": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", "$foo"}}}}}},
},
},
"TypeDotNotation": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", "$v.foo"}}}}}},
},
},
"TypeRecursive": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.D{{"$type", "$v"}}}}}}}},
},
},
"TypeRecursiveNonExistent": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.D{{"$non-existent", "$v"}}}}}}}},
},
skip: "https://github.com/FerretDB/FerretDB/issues/2678",
},
"TypeRecursiveInvalid": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.D{{"v", "$v"}}}}}}}},
},
},

"TypeInt": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", int32(42)}}}}}},
},
},
"TypeLong": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", int64(42)}}}}}},
},
},
"TypeString": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", "42"}}}}}},
},
},
"TypeDocument": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.D{{"foo", "bar"}}}}}}}},
},
},
"TypeArraySingleItem": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.A{int32(42)}}}}}}},
},
},
"TypeArray": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.A{"foo", "bar"}}}}}}},
},
skip: "https://github.com/FerretDB/FerretDB/issues/2678",
},
"TypeNestedArray": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", bson.A{bson.A{"foo", "bar"}}}}}}}},
},
},
"TypeObjectID": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", primitive.NewObjectID()}}}}}},
},
},
"TypeBool": {
pipeline: bson.A{
bson.D{{"$sort", bson.D{{"_id", -1}}}},
bson.D{{"$project", bson.D{{"type", bson.D{{"$type", true}}}}}},
},
},
}

Expand Down
11 changes: 11 additions & 0 deletions integration/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,14 @@ func FindAll(t testing.TB, ctx context.Context, collection *mongo.Collection) []

return FetchAll(t, ctx, cursor)
}

// generateDocuments generates documents with _id ranging from startID to endID.
// It returns bson.A containing bson.D documents.
func generateDocuments(startID, endID int32) bson.A {
var docs bson.A
for i := startID; i < endID; i++ {
docs = append(docs, bson.D{{"_id", i}})
}

return docs
}
64 changes: 52 additions & 12 deletions integration/indexes_compat_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 TestIndexesCompatList(t *testing.T) {
func TestListIndexesCompat(t *testing.T) {
t.Parallel()

s := setup.SetupCompatWithOpts(t, &setup.SetupCompatOpts{
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestIndexesCompatList(t *testing.T) {
}
}

func TestIndexesCompatCreate(t *testing.T) {
func TestCreateIndexesCompat(t *testing.T) {
setup.SkipForTigrisWithReason(t, "Indexes creation is not supported for Tigris")

t.Parallel()
Expand Down Expand Up @@ -304,55 +304,62 @@ func TestCreateIndexesCommandCompat(t *testing.T) {
resultType compatTestCaseResultType // defaults to nonEmptyResult
skip string // optional, skip test with a specified reason
}{
"invalid-collection-name": {
"InvalidCollectionName": {
collectionName: 42,
key: bson.D{{"v", -1}},
indexName: "custom-name",
resultType: emptyResult,
},
"nil-collection-name": {
"NilCollectionName": {
collectionName: nil,
key: bson.D{{"v", -1}},
indexName: "custom-name",
resultType: emptyResult,
},
"index-name-not-set": {
"EmptyCollectionName": {
collectionName: "",
key: bson.D{{"v", -1}},
indexName: "custom-name",
resultType: emptyResult,
skip: "https://github.com/FerretDB/FerretDB/issues/2311",
},
"IndexNameNotSet": {
collectionName: "test",
key: bson.D{{"v", -1}},
indexName: nil,
resultType: emptyResult,
skip: "https://github.com/FerretDB/FerretDB/issues/2311",
},
"empty-index-name": {
"EmptyIndexName": {
collectionName: "test",
key: bson.D{{"v", -1}},
indexName: "",
resultType: emptyResult,
skip: "https://github.com/FerretDB/FerretDB/issues/2311",
},
"non-string-index-name": {
"NonStringIndexName": {
collectionName: "test",
key: bson.D{{"v", -1}},
indexName: 42,
resultType: emptyResult,
},
"existing-name-different-key-length": {
"ExistingNameDifferentKeyLength": {
collectionName: "test",
key: bson.D{{"_id", 1}, {"v", 1}},
indexName: "_id_", // the same name as the default index
skip: "https://github.com/FerretDB/FerretDB/issues/2311",
},
"invalid-key": {
"InvalidKey": {
collectionName: "test",
key: 42,
resultType: emptyResult,
},
"empty-key": {
"EmptyKey": {
collectionName: "test",
key: bson.D{},
resultType: emptyResult,
},
"key-not-set": {
"KeyNotSet": {
collectionName: "test",
resultType: emptyResult,
skip: "https://github.com/FerretDB/FerretDB/issues/2311",
Expand Down Expand Up @@ -436,7 +443,7 @@ func TestCreateIndexesCommandCompat(t *testing.T) {
}
}

func TestIndexesCompatDrop(t *testing.T) {
func TestDropIndexesCompat(t *testing.T) {
setup.SkipForTigrisWithReason(t, "Indexes are not supported for Tigris")

t.Parallel()
Expand Down Expand Up @@ -483,6 +490,10 @@ func TestIndexesCompatDrop(t *testing.T) {
dropIndexName: "nonexistent_1",
resultType: emptyResult,
},
"Empty": {
dropIndexName: "",
resultType: emptyResult,
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -579,6 +590,22 @@ func TestDropIndexesCommandCompat(t *testing.T) {
},
toDrop: bson.A{"v_-1", "v_1_foo_1"},
},
"MultipleIndexesByKey": {
toCreate: []mongo.IndexModel{
{Keys: bson.D{{"v", -1}}},
{Keys: bson.D{{"v.foo", -1}}},
},
toDrop: bson.A{bson.D{{"v", -1}}, bson.D{{"v.foo", -1}}},
resultType: emptyResult,
},
"NonExistentMultipleIndexes": {
toDrop: bson.A{"non-existent", "invalid"},
resultType: emptyResult,
},
"InvalidMultipleIndexType": {
toDrop: bson.A{1},
resultType: emptyResult,
},
"DocumentIndex": {
toCreate: []mongo.IndexModel{
{Keys: bson.D{{"v", -1}}},
Expand All @@ -593,6 +620,19 @@ func TestDropIndexesCommandCompat(t *testing.T) {
},
toDrop: "*",
},
"WrongExpression": {
toCreate: []mongo.IndexModel{
{Keys: bson.D{{"v", -1}}},
{Keys: bson.D{{"foo.bar", 1}}},
{Keys: bson.D{{"foo", 1}, {"bar", 1}}},
},
toDrop: "***",
resultType: emptyResult,
},
"NonExistentDescendingID": {
toDrop: bson.D{{"_id", -1}},
resultType: emptyResult,
},
"MultipleKeyIndex": {
toCreate: []mongo.IndexModel{
{Keys: bson.D{{"_id", -1}, {"v", 1}}},
Expand Down
Loading

0 comments on commit fe5cf9d

Please sign in to comment.