summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVesselina Ratcheva <vesselina.ratcheva@10gen.com>2018-01-11 17:08:47 -0500
committerVesselina Ratcheva <vesselina.ratcheva@10gen.com>2018-01-30 13:31:30 -0500
commitbff8e6e0040d659dc2d70c28b98a42e9052a8743 (patch)
tree5dbdba07f4b6cc6392148591afeb144480d29a22 /src
parente62e26b324bcf4584e53cf24f8e853842d294dba (diff)
downloadmongo-bff8e6e0040d659dc2d70c28b98a42e9052a8743.tar.gz
SERVER-31409 Create basic multi-version rollback Javascript test
Diffstat (limited to 'src')
-rw-r--r--src/mongo/shell/replsettest.js30
-rw-r--r--src/mongo/shell/servers.js58
2 files changed, 84 insertions, 4 deletions
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 94a4194eafd..c696e102cf4 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -725,6 +725,29 @@ var ReplSetTest = function(opts) {
return this.getSecondaries(timeout)[0];
};
+ this.getArbiters = function() {
+ var arbiters = [];
+ for (var i = 0; i < this.nodes.length; i++) {
+ var node = this.nodes[i];
+
+ let isArbiter = false;
+
+ assert.retryNoExcept(() => {
+ isArbiter = node.getDB('admin').isMaster('admin').arbiterOnly;
+ return true;
+ }, `Could not call 'isMaster' on ${node}.`, 3, 1000);
+
+ if (isArbiter) {
+ arbiters.push(node);
+ }
+ }
+ return arbiters;
+ };
+
+ this.getArbiter = function() {
+ return this.getArbiters()[0];
+ };
+
this.status = function(timeout) {
var master = _callIsMaster();
if (!master) {
@@ -1982,6 +2005,13 @@ var ReplSetTest = function(opts) {
};
/**
+ * Returns whether or not this ReplSetTest uses mongobridge.
+ */
+ this.usesBridge = function() {
+ return _useBridge;
+ };
+
+ /**
* Wait for a state indicator to go to a particular state or states.
*
* @param node is a single node or list of nodes, by id or conn
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 6d6390567d9..ebe96ab57bd 100644
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -94,6 +94,7 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
var convertVersionStringToArray = function(versionString) {
assert("" !== versionString, "Version strings must not be empty");
var versionArray = versionString.split('.');
+
assert.gt(versionArray.length,
1,
"MongoDB versions must have at least two components to compare, but \"" +
@@ -150,23 +151,72 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
/**
* Returns true if two version strings could represent the same version. This is true
- * if, after passing the versions through getBinVersionFor, the the versions have the
+ * if, after passing the versions through getBinVersionFor, the versions have the
* same value for each version component up through the length of the shorter version.
*
* That is, 3.2.4 compares equal to 3.2, but 3.2.4 does not compare equal to 3.2.3.
*/
MongoRunner.areBinVersionsTheSame = function(versionA, versionB) {
+ // Check for invalid version strings first.
+ convertVersionStringToArray(MongoRunner.getBinVersionFor(versionA));
+ convertVersionStringToArray(MongoRunner.getBinVersionFor(versionB));
+
+ try {
+ return (0 === MongoRunner.compareBinVersions(versionA, versionB));
+ } catch (err) {
+ // compareBinVersions() throws an error if two versions differ only by the git hash.
+ return false;
+ }
+ };
+
+ /**
+ * Compares two version strings and returns:
+ * 1, if the first is more recent
+ * 0, if they are equal
+ * -1, if the first is older
+ *
+ * Note that this function only compares up to the length of the shorter version.
+ * Because of this, minor versions will compare equal to the major versions they stem
+ * from, but major-major and minor-minor version pairs will undergo strict comparison.
+ */
+ MongoRunner.compareBinVersions = function(versionA, versionB) {
+
+ let stringA = versionA;
+ let stringB = versionB;
+
versionA = convertVersionStringToArray(MongoRunner.getBinVersionFor(versionA));
versionB = convertVersionStringToArray(MongoRunner.getBinVersionFor(versionB));
+ // Treat the githash as a separate element, if it's present.
+ versionA.push(...versionA.pop().split("-"));
+ versionB.push(...versionB.pop().split("-"));
+
var elementsToCompare = Math.min(versionA.length, versionB.length);
+
for (var i = 0; i < elementsToCompare; ++i) {
- if (versionA[i] != versionB[i]) {
- return false;
+ var elementA = versionA[i];
+ var elementB = versionB[i];
+
+ if (elementA === elementB) {
+ continue;
+ }
+
+ var numA = parseInt(elementA);
+ var numB = parseInt(elementB);
+
+ assert(!isNaN(numA) && !isNaN(numB), "Cannot compare non-equal non-numeric versions.");
+
+ if (numA > numB) {
+ return 1;
+ } else if (numA < numB) {
+ return -1;
}
+
+ assert(false, `Unreachable case. Provided versions: {${stringA}, ${stringB}}`);
}
- return true;
+
+ return 0;
};
MongoRunner.logicalOptions = {