summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/collection_autoIndexId_false.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/multiVersion/collection_autoIndexId_false.js')
-rw-r--r--jstests/multiVersion/collection_autoIndexId_false.js165
1 files changed, 82 insertions, 83 deletions
diff --git a/jstests/multiVersion/collection_autoIndexId_false.js b/jstests/multiVersion/collection_autoIndexId_false.js
index 74fe0698435..ecf7b4912e0 100644
--- a/jstests/multiVersion/collection_autoIndexId_false.js
+++ b/jstests/multiVersion/collection_autoIndexId_false.js
@@ -6,106 +6,105 @@
* documents to be deleted in the previous version.
*/
(function() {
- 'use strict';
- load('jstests/libs/get_index_helpers.js');
-
- const dbName = 'test';
- const collName = 'collection_autoIndexId_false';
-
- // Given a dbpath to a 3.6 server, attempt to upgrade to 4.0.
- function upgrade36To40(dbpath) {
- let conn = MongoRunner.runMongod({binVersion: '4.0', dbpath: dbpath, noCleanData: true});
- assert.neq(null, conn, 'mongod was unable to start with version 4.0');
- let adminDb = conn.getDB('admin');
- assert.commandWorked(adminDb.runCommand({'setFeatureCompatibilityVersion': '4.0'}));
+'use strict';
+load('jstests/libs/get_index_helpers.js');
+
+const dbName = 'test';
+const collName = 'collection_autoIndexId_false';
+
+// Given a dbpath to a 3.6 server, attempt to upgrade to 4.0.
+function upgrade36To40(dbpath) {
+ let conn = MongoRunner.runMongod({binVersion: '4.0', dbpath: dbpath, noCleanData: true});
+ assert.neq(null, conn, 'mongod was unable to start with version 4.0');
+ let adminDb = conn.getDB('admin');
+ assert.commandWorked(adminDb.runCommand({'setFeatureCompatibilityVersion': '4.0'}));
+
+ MongoRunner.stopMongod(conn);
+}
+
+// Given a dbpath to a 3.6 server, attempt to upgrade to latest.
+// shouldPass determines whether or not the upgrade should be successful.
+function upgrade40ToLatest(dbpath, shouldPass) {
+ if (shouldPass) {
+ let conn = MongoRunner.runMongod({binVersion: 'latest', dbpath: dbpath, noCleanData: true});
+ assert.neq(null, conn, 'mongod failed to start with latest version');
+
+ // Ensure the _id index exists.
+ let testDb = conn.getDB(dbName);
+ let coll = testDb.getCollection(collName);
+ let spec = GetIndexHelpers.findByKeyPattern(coll.getIndexes(), {_id: 1});
+ assert.neq(null, spec);
MongoRunner.stopMongod(conn);
- }
+ } else {
+ let conn = MongoRunner.runMongod(
+ {binVersion: 'latest', dbpath: dbpath, noCleanData: true, waitForConnect: false});
- // Given a dbpath to a 3.6 server, attempt to upgrade to latest.
- // shouldPass determines whether or not the upgrade should be successful.
- function upgrade40ToLatest(dbpath, shouldPass) {
- if (shouldPass) {
- let conn =
- MongoRunner.runMongod({binVersion: 'latest', dbpath: dbpath, noCleanData: true});
- assert.neq(null, conn, 'mongod failed to start with latest version');
-
- // Ensure the _id index exists.
- let testDb = conn.getDB(dbName);
- let coll = testDb.getCollection(collName);
- let spec = GetIndexHelpers.findByKeyPattern(coll.getIndexes(), {_id: 1});
- assert.neq(null, spec);
-
- MongoRunner.stopMongod(conn);
- } else {
- let conn = MongoRunner.runMongod(
- {binVersion: 'latest', dbpath: dbpath, noCleanData: true, waitForConnect: false});
-
- // This tests that the server shuts down cleanly despite the inability to build the _id
- // index.
- assert.eq(MongoRunner.EXIT_NEED_DOWNGRADE, waitProgram(conn.pid));
- }
+ // This tests that the server shuts down cleanly despite the inability to build the _id
+ // index.
+ assert.eq(MongoRunner.EXIT_NEED_DOWNGRADE, waitProgram(conn.pid));
}
+}
- // Create a collection with autoIndexId: false on a 3.6 server and assert that an upgrade to
- // latest fails because there are duplicate values for the _id index.
- function cannotUpgradeWithDuplicateIds() {
- let conn = MongoRunner.runMongod({binVersion: '3.6'});
- assert.neq(null, conn, 'mongod was unable able to start with version 3.6');
+// Create a collection with autoIndexId: false on a 3.6 server and assert that an upgrade to
+// latest fails because there are duplicate values for the _id index.
+function cannotUpgradeWithDuplicateIds() {
+ let conn = MongoRunner.runMongod({binVersion: '3.6'});
+ assert.neq(null, conn, 'mongod was unable able to start with version 3.6');
- const dbpath = conn.dbpath;
+ const dbpath = conn.dbpath;
- // Create a collection with autoIndexId: false.
- let testDb = conn.getDB(dbName);
- let coll = testDb.getCollection(collName);
- assert.commandWorked(coll.runCommand('create', {autoIndexId: false}));
- assert.commandWorked(coll.insert({_id: 0, a: 1}));
- assert.commandWorked(coll.insert({_id: 0, a: 2}));
- MongoRunner.stopMongod(conn);
+ // Create a collection with autoIndexId: false.
+ let testDb = conn.getDB(dbName);
+ let coll = testDb.getCollection(collName);
+ assert.commandWorked(coll.runCommand('create', {autoIndexId: false}));
+ assert.commandWorked(coll.insert({_id: 0, a: 1}));
+ assert.commandWorked(coll.insert({_id: 0, a: 2}));
+ MongoRunner.stopMongod(conn);
- // The upgrade to 4.0 should always succeed because it does not care about the _id index.
- upgrade36To40(dbpath);
+ // The upgrade to 4.0 should always succeed because it does not care about the _id index.
+ upgrade36To40(dbpath);
- let shouldPass = false;
- upgrade40ToLatest(dbpath, shouldPass);
+ let shouldPass = false;
+ upgrade40ToLatest(dbpath, shouldPass);
- // Remove the duplicate (now in 4.0) and retry the upgrade to 4.2.
- conn = MongoRunner.runMongod({binVersion: '4.0', dbpath: dbpath, noCleanData: true});
- testDb = conn.getDB(dbName);
- coll = testDb.getCollection(collName);
- assert.commandWorked(coll.remove({_id: 0, a: 2}));
- MongoRunner.stopMongod(conn);
+ // Remove the duplicate (now in 4.0) and retry the upgrade to 4.2.
+ conn = MongoRunner.runMongod({binVersion: '4.0', dbpath: dbpath, noCleanData: true});
+ testDb = conn.getDB(dbName);
+ coll = testDb.getCollection(collName);
+ assert.commandWorked(coll.remove({_id: 0, a: 2}));
+ MongoRunner.stopMongod(conn);
- shouldPass = true;
- upgrade40ToLatest(dbpath, shouldPass);
+ shouldPass = true;
+ upgrade40ToLatest(dbpath, shouldPass);
- resetDbpath(dbpath);
- }
+ resetDbpath(dbpath);
+}
- // Create a collection with autoIndexId: false on a 3.6 server and assert that an upgrade to
- // latest succeeds because the missing _id index is built.
- function canUpgradeWithoutIndex() {
- let conn = MongoRunner.runMongod({binVersion: '3.6'});
- assert.neq(null, conn, 'mongod was unable able to start with version 3.6');
+// Create a collection with autoIndexId: false on a 3.6 server and assert that an upgrade to
+// latest succeeds because the missing _id index is built.
+function canUpgradeWithoutIndex() {
+ let conn = MongoRunner.runMongod({binVersion: '3.6'});
+ assert.neq(null, conn, 'mongod was unable able to start with version 3.6');
- const dbpath = conn.dbpath;
+ const dbpath = conn.dbpath;
- // Create a collection with autoIndexId: false.
- let testDb = conn.getDB(dbName);
- let coll = testDb.getCollection(collName);
- assert.commandWorked(coll.runCommand('create', {autoIndexId: false}));
- assert.commandWorked(coll.insert({_id: 0, a: 1}));
- MongoRunner.stopMongod(conn);
+ // Create a collection with autoIndexId: false.
+ let testDb = conn.getDB(dbName);
+ let coll = testDb.getCollection(collName);
+ assert.commandWorked(coll.runCommand('create', {autoIndexId: false}));
+ assert.commandWorked(coll.insert({_id: 0, a: 1}));
+ MongoRunner.stopMongod(conn);
- // The upgrade to 4.0 should always succeed because it does not care about the _id index.
- upgrade36To40(dbpath);
+ // The upgrade to 4.0 should always succeed because it does not care about the _id index.
+ upgrade36To40(dbpath);
- const shouldPass = true;
- upgrade40ToLatest(dbpath, shouldPass);
+ const shouldPass = true;
+ upgrade40ToLatest(dbpath, shouldPass);
- resetDbpath(dbpath);
- }
+ resetDbpath(dbpath);
+}
- cannotUpgradeWithDuplicateIds();
- canUpgradeWithoutIndex();
+cannotUpgradeWithDuplicateIds();
+canUpgradeWithoutIndex();
})();