diff options
author | Mindaugas Malinauskas <mindaugas.malinauskas@mongodb.com> | 2020-12-04 16:15:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-04 20:13:01 +0000 |
commit | 8bf46f814c9e3818afb19d8d045b07bb6ed594a1 (patch) | |
tree | 7508b483b80ee2b17e6ed8b420a0eed41667e20b /jstests/core/profile2.js | |
parent | 1c0f7fc1b37c4495179765bd099bab5b603b76d5 (diff) | |
download | mongo-8bf46f814c9e3818afb19d8d045b07bb6ed594a1.tar.gz |
SERVER-53234 jstests/core/profile2.js fails when background operations are run against test database
Diffstat (limited to 'jstests/core/profile2.js')
-rw-r--r-- | jstests/core/profile2.js | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/jstests/core/profile2.js b/jstests/core/profile2.js index dd7dc61f23a..4694f5b8c6c 100644 --- a/jstests/core/profile2.js +++ b/jstests/core/profile2.js @@ -12,6 +12,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) { @@ -21,14 +34,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(); @@ -37,15 +45,10 @@ assert.commandWorked(coll.getDB().runCommand({profile: 2})); // Test update with large string element in query portion. assert.commandWorked(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(); @@ -54,15 +57,10 @@ assert.commandWorked(coll.getDB().runCommand({profile: 2})); // Test update with large string element in update portion. assert.commandWorked(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(); @@ -75,13 +73,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})); |