Skip to content

Commit

Permalink
Make aggregate stats integration tests pass for SQLite (FerretDB#3151)
Browse files Browse the repository at this point in the history
  • Loading branch information
noisersup authored and yonarw committed Aug 31, 2023
1 parent f7dc029 commit fa74625
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
54 changes: 34 additions & 20 deletions integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ func TestAggregateAddFieldsErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down Expand Up @@ -194,12 +196,14 @@ func TestAggregateGroupErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down Expand Up @@ -515,12 +519,14 @@ func TestAggregateProjectErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down Expand Up @@ -566,12 +572,14 @@ func TestAggregateSetErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down Expand Up @@ -767,12 +775,14 @@ func TestAggregateUnsetErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.pipeline, "pipeline must not be nil")
require.NotNil(t, tc.err, "err must not be nil")
Expand Down Expand Up @@ -960,12 +970,14 @@ func TestAggregateCommandMaxTimeMSErrors(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

require.NotNil(t, tc.err, "err must not be nil")

Expand Down Expand Up @@ -1079,12 +1091,14 @@ func TestAggregateCommandCursor(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Parallel()
tt.Parallel()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

var pipeline any = bson.A{}
if tc.pipeline != nil {
Expand Down
31 changes: 19 additions & 12 deletions integration/aggregate_stats_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/FerretDB/FerretDB/integration/shareddata"
)

func TestAggregateCompatCollStats(t *testing.T) {
t.Parallel()
func TestAggregateCompatCollStats(tt *testing.T) {
tt.Parallel()

for name, tc := range map[string]struct {
skip string // skip test for all handlers, must have issue number mentioned
Expand Down Expand Up @@ -65,16 +65,16 @@ func TestAggregateCompatCollStats(t *testing.T) {
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
tt.Run(name, func(tt *testing.T) {
if tc.skip != "" {
t.Skip(tc.skip)
tt.Skip(tc.skip)
}

t.Helper()
t.Parallel()
tt.Helper()
tt.Parallel()

// It's enough to use a couple of providers: one for some collection and one for a non-existent collection.
s := setup.SetupCompatWithOpts(t, &setup.SetupCompatOpts{
s := setup.SetupCompatWithOpts(tt, &setup.SetupCompatOpts{
Providers: []shareddata.Provider{shareddata.ArrayDocuments},
AddNonExistentCollection: true,
})
Expand All @@ -85,8 +85,10 @@ func TestAggregateCompatCollStats(t *testing.T) {
targetCollection := targetCollections[i]
compatCollection := compatCollections[i]

t.Run(targetCollection.Name(), func(t *testing.T) {
t.Helper()
tt.Run(targetCollection.Name(), func(tt *testing.T) {
tt.Helper()

t := setup.FailsForSQLite(tt, "https://github.com/FerretDB/FerretDB/issues/3148")

command := bson.A{bson.D{{"$collStats", tc.collStats}}}

Expand Down Expand Up @@ -132,13 +134,18 @@ func TestAggregateCompatCollStats(t *testing.T) {
})
}

// TODO https://github.com/FerretDB/FerretDB/issues/3148
if setup.IsSQLite(tt) {
return
}

switch tc.resultType {
case nonEmptyResult:
assert.True(t, nonEmptyResults, "expected non-empty results (some documents should be modified)")
assert.True(tt, nonEmptyResults, "expected non-empty results (some documents should be modified)")
case emptyResult:
assert.False(t, nonEmptyResults, "expected empty results (no documents should be modified)")
assert.False(tt, nonEmptyResults, "expected empty results (no documents should be modified)")
default:
t.Fatalf("unknown result type %v", tc.resultType)
tt.Fatalf("unknown result type %v", tc.resultType)
}
})
}
Expand Down
7 changes: 7 additions & 0 deletions integration/setup/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func IsMongoDB(tb testtb.TB) bool {
return *targetBackendF == "mongodb"
}

// IsSQLite returns true if the current test is running for SQLite.
//
// This function should not be used lightly.
func IsSQLite(tb testtb.TB) bool {
return *targetBackendF == "ferretdb-sqlite"
}

// FailsForFerretDB return testtb.TB that expects test to fail for FerretDB and pass for MongoDB.
//
// This function should not be used lightly and always with an issue URL.
Expand Down

0 comments on commit fa74625

Please sign in to comment.