summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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}));