forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_compatibility_version.js
103 lines (81 loc) · 4.45 KB
/
feature_compatibility_version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Tests that manipulating the featureCompatibilityVersion document in admin.system.version changes
// the value of the featureCompatibilityVersion server parameter.
(function() {
"use strict";
load("jstests/libs/feature_compatibility_version.js");
// Skip collection validation since this test leaves collections in an invalid state, where
// FCV=3.4 but UUIDs exist.
TestData.skipCollectionAndIndexValidation = true;
/**
* Checks that the featureCompatibilityVersion document is missing, and the
* featureCompatibilityVersion server parameter is "3.4".
*/
let checkFCVDocumentMissing = function(adminDB) {
assert.eq(null, adminDB.system.version.findOne({_id: "featureCompatibilityVersion"}));
};
const conn = MongoRunner.runMongod({});
assert.neq(null, conn, "mongod was unable to start up");
let adminDB = conn.getDB("admin");
// Initially the featureCompatibilityVersion is 3.6.
checkFCV(adminDB, "3.6");
// Updating the featureCompatibilityVersion document changes the featureCompatibilityVersion
// server parameter.
assert.writeOK(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {version: "3.4"}}));
checkFCV(adminDB, "3.4");
assert.writeOK(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {version: "3.4", targetVersion: "3.6"}}));
checkFCV(adminDB, "3.4", "3.6");
assert.writeOK(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {version: "3.4", targetVersion: "3.4"}}));
checkFCV(adminDB, "3.4", "3.4");
assert.writeOK(
adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {version: "3.6"}, $unset: {targetVersion: true}}));
checkFCV(adminDB, "3.6");
// Updating the featureCompatibilityVersion document with an invalid version fails.
assert.writeErrorWithCode(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {version: "3.2"}}),
ErrorCodes.BadValue);
checkFCV(adminDB, "3.6");
// Updating the featureCompatibilityVersion document with an invalid targetVersion fails.
assert.writeErrorWithCode(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {targetVersion: "3.4"}}),
ErrorCodes.BadValue);
checkFCV(adminDB, "3.6");
assert.writeErrorWithCode(adminDB.system.version.update({_id: "featureCompatibilityVersion"},
{$set: {targetVersion: "3.6"}}),
ErrorCodes.BadValue);
checkFCV(adminDB, "3.6");
// Deleting the featureCompatibilityVersion document changes the featureCompatibilityVersion
// server parameter to 3.4.
removeFCVDocument(adminDB);
checkFCVDocumentMissing(adminDB);
// Inserting a featureCompatibilityVersion document with an invalid version fails.
assert.writeErrorWithCode(
adminDB.system.version.insert({_id: "featureCompatibilityVersion", version: "3.2"}),
ErrorCodes.BadValue);
checkFCVDocumentMissing(adminDB);
assert.writeErrorWithCode(
adminDB.system.version.insert({_id: "featureCompatibilityVersion", version: "3.8"}),
ErrorCodes.BadValue);
checkFCVDocumentMissing(adminDB);
// Inserting a featureCompatibilityVersion document with an invalid targetVersion fails.
assert.writeErrorWithCode(
adminDB.system.version.insert(
{_id: "featureCompatibilityVersion", version: "3.6", targetVersion: "3.4"}),
ErrorCodes.BadValue);
checkFCVDocumentMissing(adminDB);
assert.writeErrorWithCode(
adminDB.system.version.insert(
{_id: "featureCompatibilityVersion", version: "3.6", targetVersion: "3.6"}),
ErrorCodes.BadValue);
checkFCVDocumentMissing(adminDB);
assert.writeOK(
adminDB.system.version.insert({_id: "featureCompatibilityVersion", version: "3.6"}));
checkFCV(adminDB, "3.6");
// Dropping the admin database changes the featureCompatibilityVersion server parameter to 3.4.
adminDB.dropDatabase();
checkFCVDocumentMissing(adminDB);
MongoRunner.stopMongod(conn);
}());