(function() {
|
"use strict";
|
|
load("jstests/libs/parallelTester.js"); // for ScopedThread and CountDownLatch
|
|
const rst = new ReplSetTest({nodes: 1});
|
rst.startSet();
|
rst.initiate();
|
|
function setFCV(host, version, barrier) {
|
const conn = new Mongo(host);
|
|
barrier.countDown();
|
barrier.await();
|
|
try {
|
assert.commandWorked(conn.adminCommand({setFeatureCompatibilityVersion: version}));
|
return {ok: 1};
|
} catch (e) {
|
return {ok: 0, error: e.toString(), stack: e.stack};
|
}
|
}
|
|
const primary = rst.getPrimary();
|
const db = primary.getDB("test");
|
|
while (true) {
|
// We create two threads: one to set the server's featureCompatibilityVersion to "3.4" and
|
// another to set the server's featureCompatibilityVersion to "3.6".
|
{
|
const barrier = new CountDownLatch(2);
|
const thread34 = new ScopedThread(setFCV, primary.host, "3.4", barrier);
|
const thread36 = new ScopedThread(setFCV, primary.host, "3.6", barrier);
|
|
thread34.start();
|
thread36.start();
|
|
thread34.join();
|
thread36.join();
|
|
assert.commandWorked(thread34.returnData());
|
assert.commandWorked(thread36.returnData());
|
}
|
|
// If the thread that sets the server's featureCompatibilityVersion to "3.4" did its update
|
// to the featureCompatibilityVersion document last, then we reset the server's
|
// featureCompatibilityVersion to "3.6" and try again.
|
{
|
const res = assert.commandWorked(
|
db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}));
|
|
if (res.featureCompatibilityVersion === "3.4") {
|
assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: "3.6"}));
|
continue;
|
}
|
}
|
|
// Otherwise, we implicitly create a collection via an insert operation and verify that
|
// collections are always created with UUIDs when the server's featureCompatibilityVersion
|
// is "3.6".
|
{
|
db.mycoll.drop();
|
assert.writeOK(db.mycoll.insert({}));
|
|
const collectionInfos = db.getCollectionInfos({name: "mycoll"});
|
assert.eq(1, collectionInfos.length, tojson(collectionInfos));
|
assert(collectionInfos[0].info.hasOwnProperty("uuid"),
|
"Expected collection to have a UUID since featureCompatibilityVersion is 3.6: " +
|
tojson(collectionInfos));
|
}
|
}
|
|
rst.stopSet();
|
})();
|