Skip to content

Commit

Permalink
Clean up integration test provider setup (#3052)
Browse files Browse the repository at this point in the history
Closes #2184.
  • Loading branch information
chilagrow authored Jul 17, 2023
1 parent 70f33ed commit fed08e6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 64 deletions.
84 changes: 31 additions & 53 deletions integration/aggregate_documents_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,55 +396,15 @@ func TestAggregateCompatCount(t *testing.T) {
func TestAggregateCompatGroupDeterministicCollections(t *testing.T) {
t.Parallel()

// Scalars collection is not included because aggregation groups
// numbers of different types for $group, and this causes output
// _id to be different number type between compat and target.
// https://github.com/FerretDB/FerretDB/issues/2184
//
// Composites, ArrayStrings, ArrayInt32s and ArrayAndDocuments are not included
// Composites, ArrayStrings, ArrayInt32s, ArrayAndDocuments and Mixed are not included
// because the order in compat and target can be not deterministic.
// Aggregation assigns BSON array to output _id, and an array with
// descending sort use the greatest element for comparison causing
// multiple documents with the same greatest element the same order,
// so compat and target results in different order.
// https://github.com/FerretDB/FerretDB/issues/2185

providers := []shareddata.Provider{
// shareddata.Scalars,

shareddata.Doubles,
shareddata.OverflowVergeDoubles,
shareddata.SmallDoubles,
shareddata.Strings,
shareddata.Binaries,
shareddata.ObjectIDs,
shareddata.Bools,
shareddata.DateTimes,
shareddata.Nulls,
shareddata.Regexes,
shareddata.Int32s,
shareddata.Timestamps,
shareddata.Int64s,
shareddata.Unsets,
shareddata.ObjectIDKeys,

// shareddata.Composites,
shareddata.PostgresEdgeCases,

shareddata.DocumentsDoubles,
shareddata.DocumentsStrings,
shareddata.DocumentsDocuments,

// shareddata.ArrayStrings,
shareddata.ArrayDoubles,
// shareddata.ArrayInt32s,
shareddata.ArrayRegexes,
shareddata.ArrayDocuments,

// shareddata.Mixed,
// shareddata.ArrayAndDocuments,
}

providers := shareddata.AllProviders().Remove(shareddata.Composites, shareddata.ArrayStrings, shareddata.ArrayInt32s, shareddata.ArrayAndDocuments, shareddata.Mixed)
testCases := map[string]aggregateStagesCompatTestCase{
"DistinctValue": {
pipeline: bson.A{
Expand All @@ -458,6 +418,21 @@ func TestAggregateCompatGroupDeterministicCollections(t *testing.T) {
bson.D{{"$sort", bson.D{{"_id", -1}}}},
},
},
"Distinct": {
pipeline: bson.A{
// sort collection to ensure the order is consistent
bson.D{{"$sort", bson.D{{"_id", 1}}}},
bson.D{{"$group", bson.D{
{"_id", "$v"},
// set first _id of the collection as group's unique value
{"unique", bson.D{{"$first", "$_id"}}},
}}},
// ensure output is ordered by the _id of the collection, not _id of the group
// because _id of group can be an array
bson.D{{"$sort", bson.D{{"unique", 1}}}},
},
skip: "https://github.com/FerretDB/FerretDB/issues/2185",
},
"CountValue": {
pipeline: bson.A{
// sort to assure the same type of values (while grouping 2 types with the same value,
Expand Down Expand Up @@ -657,12 +632,12 @@ func TestAggregateCompatGroupExpressionDottedFields(t *testing.T) {

// TODO Use all providers after fixing $sort problem: https://github.com/FerretDB/FerretDB/issues/2276.
//
// Currently, providers Composites, DocumentsDeeplyNested and Mixed
// Currently, providers Composites, DocumentsDeeplyNested, ArrayAndDocuments and Mixed
// cannot be used due to sorting difference.
// FerretDB always sorts empty array is less than null.
// In compat, for `.sort()` an empty array is less than null.
// In compat, for aggregation `$sort` null is less than an empty array.
providers := shareddata.AllProviders().Remove("Mixed", "Composites", "DocumentsDeeplyNested")
providers := shareddata.AllProviders().Remove(shareddata.Mixed, shareddata.Composites, shareddata.DocumentsDeeplyNested, shareddata.ArrayAndDocuments)

testCases := map[string]aggregateStagesCompatTestCase{
"NestedInDocument": {
Expand Down Expand Up @@ -897,16 +872,16 @@ func TestAggregateCompatGroupSum(t *testing.T) {

providers := shareddata.AllProviders().
// skipped due to https://github.com/FerretDB/FerretDB/issues/2185.
Remove("Composites").
Remove("ArrayStrings").
Remove("ArrayInt32s").
Remove("Mixed").
Remove("ArrayAndDocuments").
Remove(shareddata.Composites).
Remove(shareddata.ArrayStrings).
Remove(shareddata.ArrayInt32s).
Remove(shareddata.Mixed).
Remove(shareddata.ArrayAndDocuments).
// TODO: handle $sum of doubles near max precision.
// https://github.com/FerretDB/FerretDB/issues/2300
Remove("Doubles").
Remove(shareddata.Doubles).
// TODO: https://github.com/FerretDB/FerretDB/issues/2616
Remove("ArrayDocuments")
Remove(shareddata.ArrayDocuments)

testCases := map[string]aggregateStagesCompatTestCase{
"GroupNullID": {
Expand Down Expand Up @@ -1107,6 +1082,9 @@ func TestAggregateCompatGroupSum(t *testing.T) {
func TestAggregateCompatMatch(t *testing.T) {
t.Parallel()

// TODO https://github.com/FerretDB/FerretDB/issues/2291
providers := shareddata.AllProviders().Remove(shareddata.ArrayAndDocuments)

testCases := map[string]aggregateStagesCompatTestCase{
"ID": {
pipeline: bson.A{bson.D{{"$match", bson.D{{"_id", "string"}}}}},
Expand Down Expand Up @@ -1154,7 +1132,7 @@ func TestAggregateCompatMatch(t *testing.T) {
},
}

testAggregateStagesCompat(t, testCases)
testAggregateStagesCompatWithProviders(t, providers, testCases)
}

func TestAggregateCompatSort(t *testing.T) {
Expand Down Expand Up @@ -1237,7 +1215,7 @@ func TestAggregateCompatSortDotNotation(t *testing.T) {

providers := shareddata.AllProviders().
// TODO: https://github.com/FerretDB/FerretDB/issues/2617
Remove("ArrayDocuments")
Remove(shareddata.ArrayDocuments)

testCases := map[string]aggregateStagesCompatTestCase{
"DotNotation": {
Expand Down
2 changes: 1 addition & 1 deletion integration/distinct_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func testDistinctCompat(t *testing.T, testCases map[string]distinctCompatTestCas
// Use shared setup because distinct queries can't modify data.
// TODO Use read-only user. https://github.com/FerretDB/FerretDB/issues/1025
s := setup.SetupCompatWithOpts(t, &setup.SetupCompatOpts{
Providers: shareddata.AllProviders().Remove("Scalars"), // Remove provider with the same values with different types
Providers: shareddata.AllProviders().Remove(shareddata.Scalars), // Remove provider with the same values with different types
AddNonExistentCollection: true,
})
ctx, targetCollections, compatCollections := s.Ctx, s.TargetCollections, s.CompatCollections
Expand Down
10 changes: 8 additions & 2 deletions integration/query_comparison_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ func TestQueryComparisonCompatLte(t *testing.T) {
func TestQueryComparisonCompatNin(t *testing.T) {
t.Parallel()

// TODO https://github.com/FerretDB/FerretDB/issues/2291
providers := shareddata.AllProviders().Remove(shareddata.ArrayAndDocuments)

var scalarDataTypesFilter bson.A
for _, scalarDataType := range shareddata.Scalars.Docs() {
scalarDataTypesFilter = append(scalarDataTypesFilter, scalarDataType.Map()["v"])
Expand Down Expand Up @@ -1071,12 +1074,15 @@ func TestQueryComparisonCompatNin(t *testing.T) {
},
}

testQueryCompat(t, testCases)
testQueryCompatWithProviders(t, providers, testCases)
}

func TestQueryComparisonCompatIn(t *testing.T) {
t.Parallel()

// TODO https://github.com/FerretDB/FerretDB/issues/2291
providers := shareddata.AllProviders().Remove(shareddata.ArrayAndDocuments)

var scalarDataTypesFilter bson.A
for _, scalarDataType := range shareddata.Scalars.Docs() {
scalarDataTypesFilter = append(scalarDataTypesFilter, scalarDataType.Map()["v"])
Expand Down Expand Up @@ -1113,7 +1119,7 @@ func TestQueryComparisonCompatIn(t *testing.T) {
},
}

testQueryCompat(t, testCases)
testQueryCompatWithProviders(t, providers, testCases)
}

func TestQueryComparisonCompatNe(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion integration/query_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestQueryCompatSortDotNotation(t *testing.T) {

providers := shareddata.AllProviders().
// TODO: https://github.com/FerretDB/FerretDB/issues/2618
Remove("ArrayDocuments")
Remove(shareddata.ArrayDocuments)

testCases := map[string]queryCompatTestCase{
"DotNotation": {
Expand Down
5 changes: 4 additions & 1 deletion integration/query_projection_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func TestQueryProjectionCompat(t *testing.T) {
func TestQueryProjectionPositionalOperatorCompat(t *testing.T) {
t.Parallel()

// TODO https://github.com/FerretDB/FerretDB/issues/3053
providers := shareddata.AllProviders().Remove(shareddata.ArrayAndDocuments)

testCases := map[string]queryCompatTestCase{
"IDFilter": {
// it returns error only if collection contains a doc that matches the filter
Expand Down Expand Up @@ -341,5 +344,5 @@ func TestQueryProjectionPositionalOperatorCompat(t *testing.T) {
},
}

testQueryCompat(t, testCases)
testQueryCompatWithProviders(t, providers, testCases)
}
9 changes: 4 additions & 5 deletions integration/shareddata/shareddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func AllProviders() Providers {
ArrayDocuments,

Mixed,
// TODO https://github.com/FerretDB/FerretDB/issues/2291
// ArrayAndDocuments,
ArrayAndDocuments,
}

// check that names are unique and randomize order
Expand All @@ -78,14 +77,14 @@ func AllProviders() Providers {
type Providers []Provider

// Remove specified providers and return remaining providers.
func (ps Providers) Remove(removeProviderNames ...string) Providers {
func (ps Providers) Remove(removeProviders ...Provider) Providers {
res := make([]Provider, 0, len(ps))

for _, p := range ps {
keep := true

for _, name := range removeProviderNames {
if p.Name() == name {
for _, removeProvider := range removeProviders {
if p == removeProvider {
keep = false
break
}
Expand Down
2 changes: 1 addition & 1 deletion integration/update_field_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ func TestUpdateFieldCompatMul(t *testing.T) {
providers := shareddata.AllProviders().
// OverflowVergeDoubles and Scalars contain numbers that produces +INF on compat,
// validation error on target upon $mul operation.
Remove("OverflowVergeDoubles", "Scalars")
Remove(shareddata.OverflowVergeDoubles, shareddata.Scalars)

testCases := map[string]updateCompatTestCase{
"Int32": {
Expand Down

0 comments on commit fed08e6

Please sign in to comment.