summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMindaugas Malinauskas <mindaugas.malinauskas@mongodb.com>2020-12-04 16:15:04 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-08 10:20:00 +0000
commit319538a8078c02328595848eb4281c2b6e795e98 (patch)
tree6fe5413cb2af2e4b21f75c7b6753e02b62f8462f
parent81aebe8efa47c989593a22643685804cf63bb90c (diff)
downloadmongo-319538a8078c02328595848eb4281c2b6e795e98.tar.gz
SERVER-53234 jstests/core/profile2.js fails when background operations are run against test database
(cherry picked from commit 8bf46f814c9e3818afb19d8d045b07bb6ed594a1)
-rw-r--r--jstests/core/profile2.js62
1 files changed, 28 insertions, 34 deletions
diff --git a/jstests/core/profile2.js b/jstests/core/profile2.js
index d71471b2e5f..8fe653b35fd 100644
--- a/jstests/core/profile2.js
+++ b/jstests/core/profile2.js
@@ -10,6 +10,19 @@ coll.drop();
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));
+/**
+ * Asserts that array 'results' contains a profiler generated document that corresponds to a
+ * truncated command that matches a regular expression 'truncatedCommandRegexp'. Outputs a message
+ * 'message' in case such document is not present.
+ */
+function assertContainsTruncatedCommand(results, truncatedCommandRegexp, message) {
+ const document = results.find(
+ element => element.hasOwnProperty('ns') && element.hasOwnProperty('millis') &&
+ element.hasOwnProperty('command') && 'string' === typeof (element.command.$truncated) &&
+ element.command.$truncated.match(truncatedCommandRegexp));
+ assert(document, message + ` Retrieved documents: ${tojson(results)}`);
+}
+
var str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var hugeStr = str;
while (hugeStr.length < 2 * 1024 * 1024) {
@@ -19,14 +32,9 @@ while (hugeStr.length < 2 * 1024 * 1024) {
// Test query with large string element.
coll.find({a: hugeStr}).itcount();
var results = coll.getDB().system.profile.find().toArray();
-assert.eq(1, results.length);
-var result = results[0];
-assert(result.hasOwnProperty('ns'));
-assert(result.hasOwnProperty('millis'));
-assert(result.hasOwnProperty('command'));
-assert.eq('string', typeof (result.command.$truncated));
-// String value is truncated.
-assert(result.command.$truncated.match(/filter: { a: "a+\.\.\." }/));
+assertContainsTruncatedCommand(results,
+ /filter: { a: "a+\.\.\." }//* string value is truncated*/,
+ "Document corresponding to 'find' command not found.");
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
@@ -35,15 +43,10 @@ assert.commandWorked(coll.getDB().runCommand({profile: 2}));
// Test update with large string element in query portion.
assert.writeOK(coll.update({a: hugeStr}, {}));
var results = coll.getDB().system.profile.find().toArray();
-assert.eq(1, results.length);
-var result = results[0];
-assert(result.hasOwnProperty('ns'));
-assert(result.hasOwnProperty('millis'));
-assert(result.hasOwnProperty('command'));
-assert.eq('string', typeof (result.command.$truncated));
-// String value is truncated.
-assert(result.command.$truncated.match(
- /^{ q: { a: "a+\.\.\." }, u: {}, multi: false, upsert: false }$/));
+assertContainsTruncatedCommand(
+ results,
+ /^{ q: { a: "a+\.\.\." }, u: {}, multi: false, upsert: false }$//* string value is truncated*/,
+ "Document corresponding to 'update' command not found.");
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
@@ -52,15 +55,10 @@ assert.commandWorked(coll.getDB().runCommand({profile: 2}));
// Test update with large string element in update portion.
assert.writeOK(coll.update({}, {a: hugeStr}));
var results = coll.getDB().system.profile.find().toArray();
-assert.eq(1, results.length);
-var result = results[0];
-assert(result.hasOwnProperty('ns'));
-assert(result.hasOwnProperty('millis'));
-assert(result.hasOwnProperty('command'));
-assert.eq('string', typeof (result.command.$truncated));
-// String value is truncated.
-assert(result.command.$truncated.match(
- /^{ q: {}, u: { a: "a+\.\.\." }, multi: false, upsert: false }$/));
+assertContainsTruncatedCommand(
+ results,
+ /^{ q: {}, u: { a: "a+\.\.\." }, multi: false, upsert: false }$//* string value is truncated*/,
+ "Document corresponding to 'update' command not found.");
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
@@ -73,13 +71,9 @@ for (var i = 0; i < 100 * 1000; ++i) {
}
coll.find(doc).itcount();
var results = coll.getDB().system.profile.find().toArray();
-assert.eq(1, results.length);
-var result = results[0];
-assert(result.hasOwnProperty('ns'));
-assert(result.hasOwnProperty('millis'));
-assert(result.hasOwnProperty('command'));
-assert.eq('string', typeof (result.command.$truncated));
-// Query object itself is truncated.
-assert(result.command.$truncated.match(/filter: { a0: 1\.0, a1: .*\.\.\.$/));
+assertContainsTruncatedCommand(
+ results,
+ /filter: { a0: 1\.0, a1: .*\.\.\.$//* query object itself is truncated*/,
+ "Document corresponding to 'find' command not found.");
assert.commandWorked(coll.getDB().runCommand({profile: 0}));