Skip to content

Commit

Permalink
Use MongoDB 7 (#3824)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Palazhchenko <alexey.palazhchenko@ferretdb.io>
Co-authored-by: Elena Grahovac <elena@grahovac.me>
  • Loading branch information
3 people authored Dec 14, 2023
1 parent b2b0aaf commit 9a15f1a
Show file tree
Hide file tree
Showing 30 changed files with 205 additions and 172 deletions.
2 changes: 1 addition & 1 deletion build/deps/legacy-mongo-shell.Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM ghcr.io/ferretdb/legacy-mongo-shell:6.0.9-1
FROM ghcr.io/ferretdb/legacy-mongo-shell:7.0.4-1
2 changes: 1 addition & 1 deletion build/deps/mongo.Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM mongo:6.0.9
FROM mongo:7.0.4
2 changes: 1 addition & 1 deletion build/version/mongodb.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.42
7.0.42
4 changes: 2 additions & 2 deletions build/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func TestGet(t *testing.T) {

assert.NotEmpty(t, v.Version)

assert.Equal(t, "6.0.42", v.MongoDBVersion)
testutil.AssertEqual(t, must.NotFail(types.NewArray(int32(6), int32(0), int32(42), int32(0))), v.MongoDBVersionArray)
assert.Equal(t, "7.0.42", v.MongoDBVersion)
testutil.AssertEqual(t, must.NotFail(types.NewArray(int32(7), int32(0), int32(42), int32(0))), v.MongoDBVersionArray)
}
8 changes: 5 additions & 3 deletions integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,9 @@ func TestAggregateCommandMaxTimeMSErrors(t *testing.T) {
err: &mongo.CommandError{
Code: 2,
Name: "BadValue",
Message: "9223372036854775807 value for maxTimeMS is out of range",
Message: "9223372036854775807 value for maxTimeMS is out of range " + shareddata.Int32Interval,
},
altMessage: "9223372036854775807 value for maxTimeMS is out of range",
},
"Double": {
command: bson.D{
Expand Down Expand Up @@ -1026,7 +1027,7 @@ func TestAggregateCommandMaxTimeMSErrors(t *testing.T) {
err: &mongo.CommandError{
Code: 2,
Name: "BadValue",
Message: "9223372036854775807 value for maxTimeMS is out of range",
Message: "9223372036854775807 value for maxTimeMS is out of range " + shareddata.Int32Interval,
},
altMessage: "1.797693134862316e+308 value for maxTimeMS is out of range",
},
Expand Down Expand Up @@ -1067,8 +1068,9 @@ func TestAggregateCommandMaxTimeMSErrors(t *testing.T) {
err: &mongo.CommandError{
Code: 2,
Name: "BadValue",
Message: "2147483648 value for maxTimeMS is out of range",
Message: "2147483648 value for maxTimeMS is out of range " + shareddata.Int32Interval,
},
altMessage: "2147483648 value for maxTimeMS is out of range",
},
"Null": {
command: bson.D{
Expand Down
5 changes: 3 additions & 2 deletions integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ func TestDatabaseName(t *testing.T) {
err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: fmt.Sprintf("Invalid namespace specified '%s.TestDatabaseName-Err'", dbName64),
Message: "db name must be at most 63 characters, found: 64",
},
altMessage: fmt.Sprintf("Invalid namespace specified '%s.TestDatabaseName-Err'", dbName64),
},
"WithASlash": {
db: "/",
Expand Down Expand Up @@ -473,7 +474,7 @@ func TestDatabaseName(t *testing.T) {
err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: `'.' is an invalid character in the database name: database.test`,
Message: `'.' is an invalid character in a db name: database.test`,
},
altMessage: `Invalid namespace specified 'database.test.TestDatabaseName-Err'`,
},
Expand Down
4 changes: 2 additions & 2 deletions integration/commands_administration_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func TestCommandsAdministrationCompatCollStatsCappedCollection(t *testing.T) {
},
"SizeRounded": {
sizeInBytes: 1000,
expectedSize: 1024,
expectedSize: 1000,
},
"MaxDocuments": {
sizeInBytes: 1,
maxDocuments: 10,
expectedSize: 256,
expectedSize: 1,
},
} {
name, tc := name, tc
Expand Down
92 changes: 41 additions & 51 deletions integration/commands_administration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,10 @@ func TestCommandsAdministrationCreateDropList(t *testing.T) {
err = db.Collection(name).Drop(ctx)
require.NoError(t, err)

// drop manually to check error
var res bson.D
err = db.RunCommand(ctx, bson.D{{"drop", name}}).Decode(&res)
expectedErr := mongo.CommandError{
Code: 26,
Name: "NamespaceNotFound",
Message: `ns not found`,
}
AssertEqualCommandError(t, expectedErr, err)

err = db.CreateCollection(ctx, name)
require.NoError(t, err)

err = db.CreateCollection(ctx, name)
expectedErr = mongo.CommandError{
Code: 48,
Name: "NamespaceExists",
Message: `Collection TestCommandsAdministrationCreateDropList.TestCommandsAdministrationCreateDropList already exists.`,
}
AssertEqualCommandError(t, expectedErr, err)

// List collection names
names, err = db.ListCollectionNames(ctx, bson.D{})
require.NoError(t, err)
assert.Contains(t, names, name)
Expand All @@ -85,14 +68,13 @@ func TestCommandsAdministrationCreateDropList(t *testing.T) {
err = collection.Drop(ctx)
require.NoError(t, err)

// drop manually to check error
// And try to drop existing collection again manually to check behavior.
var res bson.D
err = db.RunCommand(ctx, bson.D{{"drop", name}}).Decode(&res)
expectedErr = mongo.CommandError{
Code: 26,
Name: "NamespaceNotFound",
Message: `ns not found`,
}
AssertEqualCommandError(t, expectedErr, err)
assert.NoError(t, err)

actual := ConvertDocument(t, res)
assert.Equal(t, must.NotFail(actual.Get("ok")), float64(1))
}

func TestCommandsAdministrationCreateDropListDatabases(t *testing.T) {
Expand Down Expand Up @@ -542,11 +524,11 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
"EmptyParameters": {
command: bson.D{{"getParameter", 1}, {"comment", "getParameter test"}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"OnlyNonexistentParameters": {
command: bson.D{{"getParameter", 1}, {"quiet_other", 1}, {"comment", "getParameter test"}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"ShowDetailsTrue": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}}}, {"quiet", true}},
Expand All @@ -570,11 +552,11 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
"ShowDetails_NoParameter_1": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}}}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"ShowDetails_NoParameter_2": {
command: bson.D{{"getParameter", bson.D{{"showDetails", false}}}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"AllParametersTrue": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}, {"allParameters", true}}}},
Expand All @@ -589,7 +571,7 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
"AllParametersFalse_MissingParameter": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}, {"allParameters", false}}}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"AllParametersFalse_PresentParameter": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}, {"allParameters", false}}}, {"quiet", true}},
Expand All @@ -605,7 +587,7 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
"AllParametersFalse_NonexistentParameter": {
command: bson.D{{"getParameter", bson.D{{"showDetails", true}, {"allParameters", false}}}, {"quiet_other", true}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"ShowDetailsFalse_AllParametersTrue": {
command: bson.D{{"getParameter", bson.D{{"showDetails", false}, {"allParameters", true}}}},
Expand All @@ -617,7 +599,7 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
"ShowDetailsFalse_AllParametersFalse_1": {
command: bson.D{{"getParameter", bson.D{{"showDetails", false}, {"allParameters", false}}}},
err: &mongo.CommandError{Message: `no option found to get`},
err: &mongo.CommandError{Code: 72, Message: `no option found to get`, Name: "InvalidOptions"},
},
"ShowDetailsFalse_AllParametersFalse_2": {
command: bson.D{{"getParameter", bson.D{{"showDetails", false}, {"allParameters", false}}}, {"quiet", true}},
Expand Down Expand Up @@ -774,7 +756,7 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
{"featureCompatibilityVersion", 1},
},
expected: map[string]any{
"featureCompatibilityVersion": bson.D{{"version", "6.0"}},
"featureCompatibilityVersion": bson.D{{"version", "7.0"}},
"ok": float64(1),
},
},
Expand All @@ -785,7 +767,7 @@ func TestCommandsAdministrationGetParameter(t *testing.T) {
},
expected: map[string]any{
"featureCompatibilityVersion": bson.D{
{"value", bson.D{{"version", "6.0"}}},
{"value", bson.D{{"version", "7.0"}}},
{"settableAtRuntime", false},
{"settableAtStartup", false},
},
Expand Down Expand Up @@ -895,7 +877,7 @@ func TestCommandsAdministrationBuildInfo(t *testing.T) {
doc := ConvertDocument(t, actual)

assert.Equal(t, float64(1), must.NotFail(doc.Get("ok")))
assert.Regexp(t, `^6\.0\.`, must.NotFail(doc.Get("version")))
assert.Regexp(t, `^7\.0\.`, must.NotFail(doc.Get("version")))
assert.NotEmpty(t, must.NotFail(doc.Get("gitVersion")))

_, ok := must.NotFail(doc.Get("modules")).(*types.Array)
Expand All @@ -905,7 +887,7 @@ func TestCommandsAdministrationBuildInfo(t *testing.T) {

versionArray, ok := must.NotFail(doc.Get("versionArray")).(*types.Array)
assert.True(t, ok)
assert.Equal(t, int32(6), must.NotFail(versionArray.Get(0)))
assert.Equal(t, int32(7), must.NotFail(versionArray.Get(0)))
assert.Equal(t, int32(0), must.NotFail(versionArray.Get(1)))

assert.Equal(t, int32(strconv.IntSize), must.NotFail(doc.Get("bits")))
Expand Down Expand Up @@ -1215,16 +1197,18 @@ func TestCommandsAdministrationDataSizeErrors(t *testing.T) {
err: &mongo.CommandError{
Code: 73,
Name: "InvalidNamespace",
Message: "Invalid namespace specified 'invalid'",
Message: "Namespace invalid is not a valid collection name",
},
altMessage: "Invalid namespace specified 'invalid'",
},
"InvalidNamespaceTypeDocument": {
command: bson.D{{"dataSize", bson.D{}}},
err: &mongo.CommandError{
Code: 2,
Name: "BadValue",
Message: "collection name has invalid type object",
Code: 14,
Name: "TypeMismatch",
Message: "BSON field 'dataSize.dataSize' is the wrong type 'object', expected type 'string'",
},
altMessage: "collection name has invalid type object",
},
} {
name, tc := name, tc
Expand Down Expand Up @@ -1267,7 +1251,7 @@ func TestCommandsAdministrationDBStats(t *testing.T) {
assert.Equal(t, collection.Database().Name(), doc.Remove("db"))
assert.EqualValues(t, 1, doc.Remove("collections"))
assert.EqualValues(t, len(shareddata.DocumentsStrings.Docs()), doc.Remove("objects"))
assert.Equal(t, float64(1), doc.Remove("scaleFactor"))
assert.Equal(t, int64(1), doc.Remove("scaleFactor"))
assert.Equal(t, float64(1), doc.Remove("ok"))

assert.InDelta(t, 37_500, doc.Remove("avgObjSize"), 37_460)
Expand All @@ -1281,7 +1265,7 @@ func TestCommandsAdministrationDBStats(t *testing.T) {
totalFreeStorageSize, _ := doc.Get("totalFreeStorageSize")
assert.Nil(t, totalFreeStorageSize)

assert.Equal(t, int32(0), doc.Remove("views"))
assert.Equal(t, int64(0), doc.Remove("views"))
assert.EqualValues(t, 1, doc.Remove("indexes"))
assert.NotZero(t, doc.Remove("indexSize"))
}
Expand Down Expand Up @@ -1309,7 +1293,7 @@ func TestCommandsAdministrationDBStatsEmpty(t *testing.T) {
assert.InDelta(t, 35500, doc.Remove("dataSize"), 35500)
assert.InDelta(t, 16384, doc.Remove("totalSize"), 16384)

assert.Equal(t, int32(0), doc.Remove("views"))
assert.Equal(t, int64(0), doc.Remove("views"))
assert.EqualValues(t, 0, doc.Remove("indexes"))
assert.Zero(t, doc.Remove("indexSize"))
}
Expand All @@ -1328,13 +1312,13 @@ func TestCommandsAdministrationDBStatsWithScale(t *testing.T) {

assert.Equal(t, float64(1), doc.Remove("ok"))
assert.Equal(t, collection.Database().Name(), doc.Remove("db"))
assert.Equal(t, float64(1000), doc.Remove("scaleFactor"))
assert.Equal(t, int64(1000), doc.Remove("scaleFactor"))

assert.InDelta(t, 1, doc.Remove("collections"), 1)
assert.InDelta(t, 35500, doc.Remove("dataSize"), 35500)
assert.InDelta(t, 16384, doc.Remove("totalSize"), 16384)

assert.Equal(t, int32(0), doc.Remove("views"))
assert.Equal(t, int64(0), doc.Remove("views"))
assert.EqualValues(t, 1, doc.Remove("indexes"))
assert.NotZero(t, doc.Remove("indexSize"))
}
Expand Down Expand Up @@ -1362,7 +1346,7 @@ func TestCommandsAdministrationDBStatsEmptyWithScale(t *testing.T) {
assert.InDelta(t, 35500, doc.Remove("dataSize"), 35500)
assert.InDelta(t, 16384, doc.Remove("totalSize"), 16384)

assert.Equal(t, int32(0), doc.Remove("views"))
assert.Equal(t, int64(0), doc.Remove("views"))
assert.EqualValues(t, 0, doc.Remove("indexes"))
assert.Zero(t, doc.Remove("indexSize"))
}
Expand All @@ -1379,7 +1363,7 @@ func TestCommandsAdministrationDBStatsFreeStorage(t *testing.T) {

doc := ConvertDocument(t, res)

assert.Equal(t, float64(1), doc.Remove("scaleFactor"))
assert.Equal(t, int64(1), doc.Remove("scaleFactor"))
assert.Equal(t, float64(1), doc.Remove("ok"))
assert.Zero(t, must.NotFail(doc.Get("freeStorageSize")))
assert.Zero(t, must.NotFail(doc.Get("totalFreeStorageSize")))
Expand All @@ -1398,12 +1382,15 @@ func TestCommandsAdministrationServerStatus(t *testing.T) {

assert.Equal(t, float64(1), must.NotFail(doc.Get("ok")))

freeMonitoring, err := doc.Get("freeMonitoring")
require.NoError(t, err)
assert.NotEmpty(t, must.NotFail(freeMonitoring.(*types.Document).Get("state")))
t.Run("FreeMonitoring", func(t *testing.T) {
setup.SkipForMongoDB(t, "MongoDB decommissioned free monitoring")
freeMonitoring, fErr := doc.Get("freeMonitoring")
require.NoError(t, fErr)
assert.NotEmpty(t, must.NotFail(freeMonitoring.(*types.Document).Get("state")))
})

assert.NotEmpty(t, must.NotFail(doc.Get("host")))
assert.Regexp(t, `^6\.0\.`, must.NotFail(doc.Get("version")))
assert.Regexp(t, `^7\.0\.`, must.NotFail(doc.Get("version")))
assert.NotEmpty(t, must.NotFail(doc.Get("process")))

assert.GreaterOrEqual(t, must.NotFail(doc.Get("pid")), int64(1))
Expand Down Expand Up @@ -1475,6 +1462,7 @@ func TestCommandsAdministrationServerStatusMetrics(t *testing.T) {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
setup.SkipForMongoDB(t, "MongoDB decommissioned server status metrics")
ctx, collection := setup.Setup(t)

for _, cmd := range tc.cmds {
Expand Down Expand Up @@ -1514,6 +1502,8 @@ func TestCommandsAdministrationServerStatusMetrics(t *testing.T) {
}

func TestCommandsAdministrationServerStatusFreeMonitoring(t *testing.T) {
setup.SkipForMongoDB(t, "MongoDB decommissioned free monitoring")

// this test shouldn't be run in parallel, because it requires a specific state of the field which would be modified by the other tests.
s := setup.SetupWithOpts(t, &setup.SetupOpts{
DatabaseName: "admin",
Expand Down
9 changes: 7 additions & 2 deletions integration/commands_diagnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func TestCommandsDiagnosticExplain(t *testing.T) {
explainResult := actual.Map()

assert.Equal(t, float64(1), explainResult["ok"])
assert.Equal(t, "1", explainResult["explainVersion"])

// explainVersion 1 and 2 are in use for different methods on Mongo 7
assert.True(t, explainResult["explainVersion"] == "1" || explainResult["explainVersion"] == "2")
assert.Equal(t, tc.command, explainResult["command"])

serverInfo := ConvertDocument(t, explainResult["serverInfo"].(bson.D))
Expand All @@ -111,7 +113,7 @@ func TestCommandsDiagnosticExplain(t *testing.T) {
assert.NotEmpty(t, host)

assert.NotEmpty(t, gitVersion)
assert.Regexp(t, `^6\.0\.`, version)
assert.Regexp(t, `^7\.0\.`, version)

assert.NotEmpty(t, explainResult["queryPlanner"])
assert.IsType(t, bson.D{}, explainResult["queryPlanner"])
Expand Down Expand Up @@ -299,6 +301,8 @@ func TestCommandsDiagnosticValidate(t *testing.T) {
"ok", float64(1),
))

// TODO https://github.com/FerretDB/FerretDB/issues/3841
actual.Remove("uuid")
actual.Remove("keysPerIndex")
actual.Remove("indexDetails")
actual.Remove("$clusterTime")
Expand Down Expand Up @@ -337,6 +341,7 @@ func TestCommandsDiagnosticValidate(t *testing.T) {
"ok", float64(1),
))

actual.Remove("uuid")
actual.Remove("keysPerIndex")
actual.Remove("indexDetails")
actual.Remove("$clusterTime")
Expand Down
2 changes: 2 additions & 0 deletions integration/commands_freemonitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

func TestCommandsFreeMonitoringGetFreeMonitoringStatus(t *testing.T) {
t.Parallel()
setup.SkipForMongoDB(t, "MongoDB decommissioned enabling free monitoring")
s := setup.SetupWithOpts(t, &setup.SetupOpts{
DatabaseName: "admin",
})
Expand All @@ -52,6 +53,7 @@ func TestCommandsFreeMonitoringGetFreeMonitoringStatus(t *testing.T) {
}

func TestCommandsFreeMonitoringSetFreeMonitoring(t *testing.T) {
setup.SkipForMongoDB(t, "MongoDB decommissioned enabling free monitoring")
t.Parallel()
s := setup.SetupWithOpts(t, &setup.SetupOpts{
DatabaseName: "admin",
Expand Down
Loading

0 comments on commit 9a15f1a

Please sign in to comment.