summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIrina Yatsenko <irina.yatsenko@mongodb.com>2021-06-22 18:05:09 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-29 07:06:40 +0000
commitfd8bca36f6479ede90e98b34ca3110044e50cb0c (patch)
treedc93c708216a47a8db2c8624198a5f8e72583dd3
parent3ed0deecaa0e5b586d12d894f3652080c4f81b43 (diff)
downloadmongo-fd8bca36f6479ede90e98b34ca3110044e50cb0c.tar.gz
SERVER-57460 Remove remaining GLE calls from jstests
-rw-r--r--jstests/concurrency/fsm_libs/cluster.js10
-rw-r--r--jstests/core/bulk_insert_capped.js3
-rw-r--r--jstests/libs/override_methods/implicitly_retry_on_database_drop_pending.js30
-rw-r--r--jstests/libs/test_background_ops.js7
-rw-r--r--jstests/replsets/oplog_format.js13
-rw-r--r--jstests/replsets/read_committed.js3
-rw-r--r--jstests/sharding/read_pref_cmd.js35
-rw-r--r--src/mongo/shell/assert.js38
8 files changed, 27 insertions, 112 deletions
diff --git a/jstests/concurrency/fsm_libs/cluster.js b/jstests/concurrency/fsm_libs/cluster.js
index 8c3f58d43bb..5cf6c7facff 100644
--- a/jstests/concurrency/fsm_libs/cluster.js
+++ b/jstests/concurrency/fsm_libs/cluster.js
@@ -579,14 +579,8 @@ var Cluster = function(options) {
phase +
', failed to find self in replication status: ' + tojson(replSetStatus));
- // Wait for all previous workload operations to complete, with "getLastError".
- res = primary.getDB('test').runCommand({
- getLastError: 1,
- w: options.replication.numNodes,
- wtimeout: 5 * 60 * 1000,
- wOpTime: primaryInfo.optime
- });
- assert.commandWorked(res, phase + ', error awaiting replication');
+ // Wait for all previous workload operations to complete.
+ rst.awaitReplication();
}
});
};
diff --git a/jstests/core/bulk_insert_capped.js b/jstests/core/bulk_insert_capped.js
index b14881160e7..6435ca9f88b 100644
--- a/jstests/core/bulk_insert_capped.js
+++ b/jstests/core/bulk_insert_capped.js
@@ -21,8 +21,7 @@ t.drop();
db.createCollection(t.getName(), {capped: true, size: 16 * 1024, max: 1});
-t.insert([{_id: 1}, {_id: 2}]);
-assert.gleSuccess(db);
+assert.commandWorked(t.insert([{_id: 1}, {_id: 2}]));
// Ensure the collection is valid.
var res = t.validate({full: true});
diff --git a/jstests/libs/override_methods/implicitly_retry_on_database_drop_pending.js b/jstests/libs/override_methods/implicitly_retry_on_database_drop_pending.js
index 534d52a76f3..f9a72ca1d5f 100644
--- a/jstests/libs/override_methods/implicitly_retry_on_database_drop_pending.js
+++ b/jstests/libs/override_methods/implicitly_retry_on_database_drop_pending.js
@@ -10,26 +10,6 @@ const defaultTimeout = 10 * 60 * 1000;
const mongoRunCommandOriginal = Mongo.prototype.runCommand;
const mongoRunCommandWithMetadataOriginal = Mongo.prototype.runCommandWithMetadata;
-function awaitLatestOperationMajorityConfirmed(primary) {
- // Get the latest optime from the primary.
- const replSetStatus = assert.commandWorked(primary.adminCommand({replSetGetStatus: 1}),
- "error getting replication status from primary");
- const primaryInfo = replSetStatus.members.find(memberInfo => memberInfo.self);
- assert(primaryInfo !== undefined,
- "failed to find self in replication status: " + tojson(replSetStatus));
-
- // Wait for all operations until 'primaryInfo.optime' to be applied by a majority of the
- // replica set.
- assert.commandWorked( //
- primary.adminCommand({
- getLastError: 1,
- w: "majority",
- wtimeout: defaultTimeout,
- wOpTime: primaryInfo.optime,
- }),
- "error awaiting replication");
-}
-
function runCommandWithRetries(conn, dbName, commandObj, func, makeFuncArgs) {
if (typeof commandObj !== "object" || commandObj === null) {
return func.apply(conn, makeFuncArgs(commandObj));
@@ -130,17 +110,9 @@ function runCommandWithRetries(conn, dbName, commandObj, func, makeFuncArgs) {
msg += " " + tojsononeline(commandObj);
}
- msg += " failed due to the " + dbName + " database being marked as drop-pending." +
- " Waiting for the latest operation to become majority confirmed before trying" +
- " again.";
+ msg += " failed due to the " + dbName + " database being marked as drop-pending.";
print(msg);
- // We wait for the primary's latest operation to become majority confirmed.
- // However, we may still need to retry more than once because the primary may not
- // yet have generated the oplog entry for the "dropDatabase" operation while it is
- // dropping each intermediate collection.
- awaitLatestOperationMajorityConfirmed(conn);
-
if (TestData.skipDropDatabaseOnDatabaseDropPending && commandName === "dropDatabase") {
// We avoid retrying the "dropDatabase" command when another "dropDatabase"
// command was already in progress for the database. This reduces the likelihood
diff --git a/jstests/libs/test_background_ops.js b/jstests/libs/test_background_ops.js
index 1d324a4862a..f0bf0ced476 100644
--- a/jstests/libs/test_background_ops.js
+++ b/jstests/libs/test_background_ops.js
@@ -18,17 +18,16 @@ var waitForLock = function(mongo, name) {
var startTime = new Date().getTime();
assert.soon(function() {
- lockColl.update({_id: name, state: 0}, {$set: {ts: ts, state: 1}});
- var gleObj = lockColl.getDB().getLastErrorObj();
+ let res = lockColl.update({_id: name, state: 0}, {$set: {ts: ts, state: 1}});
if (new Date().getTime() - startTime > 20 * 1000) {
print("Waiting for...");
- printjson(gleObj);
+ printjson(res);
printjson(lockColl.findOne());
printjson(ts);
}
- return gleObj.n == 1 || gleObj.updatedExisting;
+ return res.nModified == 1;
}, "could not acquire lock", 30 * 1000, 100);
print("Acquired lock " + tojson({_id: name, ts: ts}) +
diff --git a/jstests/replsets/oplog_format.js b/jstests/replsets/oplog_format.js
index a03027fa625..149233e805a 100644
--- a/jstests/replsets/oplog_format.js
+++ b/jstests/replsets/oplog_format.js
@@ -163,19 +163,6 @@ assertLastOplog({_id: id, a: 200}, null, msg); // No new oplog entry
coll.remove({});
assert.eq(coll.find().itcount(), 0, "collection not empty-2");
-/* inconsistent oplog format with old code -- new is okay but less efficient
- * enable once we switch the default
-var msg = "bad array $push";
-coll.save({_id:1, a:[1,2]})
-coll.update({}, {$push:{a:3}});
-var gle = cdb.getLastErrorObj();
-assert.isnull(gle.err, msg);
-assert.eq(gle.n, 1, "update failed for '" + msg +"': "+ tojson(gle));
-assert.docEq({_id:1, a:[1,2,3]}, coll.findOne({}), msg);
-//assertLastOplog({$set:{"a.2": 3}}, {_id:1}, msg); // old format
-assertLastOplog({$set:{"a": [1,2,3]}}, {_id:1}, msg); // new format
- */
-
var msg = "bad array $push 2";
coll.save({_id: 1, a: "foo"});
res = assert.commandWorked(coll.update({}, {$push: {c: 18}}));
diff --git a/jstests/replsets/read_committed.js b/jstests/replsets/read_committed.js
index 1774ce9e9d9..33b3ff31c01 100644
--- a/jstests/replsets/read_committed.js
+++ b/jstests/replsets/read_committed.js
@@ -159,7 +159,8 @@ for (var testName in testCases) {
// Restart oplog application on the secondary and ensure the committed view is updated.
restartServerReplication(secondary);
- coll.getDB().getLastError("majority", 60 * 1000);
+ replTest.awaitLastOpCommitted();
+
assert.eq(doCommittedRead(coll), test.expectedAfter);
assert.neq(readLatestOplogEntry('majority').ts, initialOplogTs);
diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js
index 27bdedc44e3..29bd3c09463 100644
--- a/jstests/sharding/read_pref_cmd.js
+++ b/jstests/sharding/read_pref_cmd.js
@@ -31,14 +31,14 @@ TestData.skipCheckingIndexesConsistentAcrossCluster = true;
/**
* Prepares to call testConnReadPreference(), testCursorReadPreference() or testBadMode().
*/
-var setUp = function() {
+var setUp = function(rst) {
var configDB = st.s.getDB('config');
assert.commandWorked(configDB.adminCommand({enableSharding: kDbName}));
assert.commandWorked(configDB.adminCommand({shardCollection: kShardedNs, key: {x: 1}}));
// Each time we drop the database we have to re-enable profiling. Enable profiling on 'admin'
// to test the $currentOp aggregation stage.
- st.rs0.nodes.forEach(function(node) {
+ rst.nodes.forEach(function(node) {
assert(node.getDB(kDbName).setProfilingLevel(2));
assert(node.getDB('admin').setProfilingLevel(2));
});
@@ -48,10 +48,9 @@ var setUp = function() {
* Cleans up after testConnReadPreference(), testCursorReadPreference() or testBadMode(),
* prepares to call setUp() again.
*/
-var tearDown = function() {
+var tearDown = function(rst) {
assert.commandWorked(st.s.getDB(kDbName).dropDatabase());
- // Hack until SERVER-7739 gets fixed
- st.rs0.awaitReplication();
+ rst.awaitReplication();
};
/**
@@ -157,7 +156,8 @@ let assertCmdRanOnExpectedNodes = function(conn, isMongos, rsNodes, cmdTestCase)
* hedge {Object} hedge options of the form {enabled: <bool>}.
* @param expectedNode {string} which node should this run on: "primary", "secondary", or "any".
*/
-let testConnReadPreference = function(conn, isMongos, rsNodes, {readPref, expectedNode}) {
+let testConnReadPreference = function(conn, isMongos, rst, {readPref, expectedNode}) {
+ let rsNodes = rst.nodes;
jsTest.log(`Testing ${isMongos ? "mongos" : "mongod"} connection with readPreference mode: ${
readPref.mode}, tag sets: ${tojson(readPref.tagSets)}, hedge ${tojson(readPref.hedge)}`);
@@ -209,8 +209,9 @@ let testConnReadPreference = function(conn, isMongos, rsNodes, {readPref, expect
allowedOnSecondary.kNever,
false,
formatProfileQuery(kUnshardedNs, {create: kUnshardedCollName}));
+
// Make sure the unsharded collection is propagated to secondaries before proceeding.
- testDB.runCommand({getLastError: 1, w: nodeCount});
+ rst.awaitReplication();
var mapFunc = function(doc) {};
var reduceFunc = function(key, values) {
@@ -444,7 +445,7 @@ let testBadMode = function(conn, isMongos, rsNodes, readPref) {
}
};
-var testAllModes = function(conn, rsNodes, isMongos) {
+var testAllModes = function(conn, rst, isMongos) {
// The primary is tagged with { tag: "one" } and one of the secondaries is
// tagged with { tag: "two" }. We can use this to test the interaction between
// modes, tags, and hedge options. Test a bunch of combinations.
@@ -485,14 +486,14 @@ var testAllModes = function(conn, rsNodes, isMongos) {
{readPref: {mode: "nearest", hedge: {enabled: true}}, expectedNode: "any"}
].forEach(function(testCase) {
- setUp();
+ setUp(rst);
// Run testCursorReadPreference() first since testConnReadPreference() sets the connection's
// read preference.
- testCursorReadPreference(conn, isMongos, rsNodes, testCase);
- testConnReadPreference(conn, isMongos, rsNodes, testCase);
+ testCursorReadPreference(conn, isMongos, rst.nodes, testCase);
+ testConnReadPreference(conn, isMongos, rst, testCase);
- tearDown();
+ tearDown(rst);
});
[
@@ -514,9 +515,9 @@ var testAllModes = function(conn, rsNodes, isMongos) {
{readPref: {mode: "nearest", hedge: {doesnotexist: true}}},
].forEach(function(testCase) {
- setUp();
- testBadMode(conn, isMongos, rsNodes, testCase.readPref);
- tearDown();
+ setUp(rst);
+ testBadMode(conn, isMongos, rst.nodes, testCase.readPref);
+ tearDown(rst);
});
};
@@ -612,7 +613,7 @@ st.rs0.nodes.forEach(function(conn) {
assert.commandWorked(
st.s.adminCommand({setParameter: 1, logComponentVerbosity: {network: {verbosity: 3}}}));
-testAllModes(replConn, st.rs0.nodes, false);
+testAllModes(replConn, st.rs0, false);
jsTest.log('Starting test for mongos connection');
@@ -625,7 +626,7 @@ assert(replicaSetMonitorProtocol === "streamable" || replicaSetMonitorProtocol =
let failPoint = configureFailPoint(st.s, "sdamServerSelectorIgnoreLatencyWindow");
-testAllModes(st.s, st.rs0.nodes, true);
+testAllModes(st.s, st.rs0, true);
failPoint.off();
st.stop();
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js
index 5e5ff7cdeca..b40d3f2b81d 100644
--- a/src/mongo/shell/assert.js
+++ b/src/mongo/shell/assert.js
@@ -1079,24 +1079,6 @@ assert = (function() {
doassert(_buildAssertionMessage(msg, msgPrefix));
};
- assert.gleOK = function(res, msg) {
- var errMsg = null;
-
- if (!res) {
- errMsg = "missing first argument, no response to check";
- } else if (!res.ok) {
- errMsg = "getLastError failed: " + tojson(res);
- } else if ('code' in res || 'errmsg' in res || ('err' in res && res['err'] != null)) {
- errMsg = "write or write concern failed: " + tojson(res);
- }
-
- if (errMsg) {
- doassert(_buildAssertionMessage(msg, errMsg), res);
- }
-
- return res;
- };
-
assert.gleSuccess = function(dbOrGLEDoc, msg) {
var gle = dbOrGLEDoc instanceof DB ? dbOrGLEDoc.getLastErrorObj() : dbOrGLEDoc;
if (gle.err) {
@@ -1107,15 +1089,6 @@ assert = (function() {
return gle;
};
- assert.gleError = function(dbOrGLEDoc, msg) {
- var gle = dbOrGLEDoc instanceof DB ? dbOrGLEDoc.getLastErrorObj() : dbOrGLEDoc;
- if (!gle.err) {
- if (typeof (msg) == "function")
- msg = msg(gle);
- doassert(_buildAssertionMessage(msg, "getLastError is null: " + tojson(gle)));
- }
- };
-
assert.gleErrorCode = function(dbOrGLEDoc, code, msg) {
var gle = dbOrGLEDoc instanceof DB ? dbOrGLEDoc.getLastErrorObj() : dbOrGLEDoc;
if (!gle.err || gle.code != code) {
@@ -1127,17 +1100,6 @@ assert = (function() {
}
};
- assert.gleErrorRegex = function(dbOrGLEDoc, regex, msg) {
- var gle = dbOrGLEDoc instanceof DB ? dbOrGLEDoc.getLastErrorObj() : dbOrGLEDoc;
- if (!gle.err || !regex.test(gle.err)) {
- if (typeof (msg) == "function")
- msg = msg(gle);
- doassert(_buildAssertionMessage(
- msg,
- "getLastError is null or doesn't match regex (" + regex + "): " + tojson(gle)));
- }
- };
-
assert.includes = function(haystack, needle, msg) {
if (!haystack.includes(needle)) {
var assertMsg = "string [" + haystack + "] does not include [" + needle + "]";