summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorAndrii Dobroshynskyi <andrii.dobroshynskyi@mongodb.com>2020-06-25 16:56:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-30 20:53:40 +0000
commit7917051ba59a15fddf70493ffe50ec28289523ae (patch)
tree422ce2cd320ed318ff9efae02ff60156e0257ffe /jstests/core
parent5c9db8373b31516386625d02540d6492bf5be5c3 (diff)
downloadmongo-7917051ba59a15fddf70493ffe50ec28289523ae.tar.gz
SERVER-48742 Log changes to profiler settings
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/apitest_db_profile_level.js43
1 files changed, 35 insertions, 8 deletions
diff --git a/jstests/core/apitest_db_profile_level.js b/jstests/core/apitest_db_profile_level.js
index adfc2b0ee43..18ed2384726 100644
--- a/jstests/core/apitest_db_profile_level.js
+++ b/jstests/core/apitest_db_profile_level.js
@@ -6,35 +6,62 @@
(function() {
'use strict';
+load("jstests/libs/log.js"); // For findMatchingLogLine, findMatchingLogLines.
+
/*
* be sure the public collection API is complete
*/
assert(db.getProfilingLevel, "getProfilingLevel");
assert(db.setProfilingLevel, "setProfilingLevel");
+// Checks for the log that was expected to be created when profile level changed.
+function profilerChangeWasLogged({from, to} = {}) {
+ const globalLog = assert.commandWorked(profileLevelDB.adminCommand({getLog: "global"}));
+ const fieldMatcher = {msg: "Profiler settings changed"};
+ if (from && to) {
+ const lines = [...findMatchingLogLines(globalLog.log, fieldMatcher)];
+ return lines.find(line => line.match(new RegExp(/"from":{/.source + from.source)) &&
+ line.match(new RegExp(/"to":{/.source + to.source)));
+ } else {
+ return findMatchingLogLine(globalLog.log, fieldMatcher);
+ }
+}
+
// A test-specific database is used for profiler testing so as not to interfere with
// other tests that modify profiler level, when run in parallel.
var profileLevelDB = db.getSiblingDB("apitest_db_profile_level");
+profileLevelDB.getProfilingLevel();
+assert(!profilerChangeWasLogged(), "Didn't expect anything to be logged");
+
+assert.throws(() => {
+ profileLevelDB.setProfilingLevel(-1);
+});
+assert(!profilerChangeWasLogged(), "Didn't expect anything to be logged");
+
profileLevelDB.setProfilingLevel(0);
assert(profileLevelDB.getProfilingLevel() == 0, "prof level 0");
+assert(profilerChangeWasLogged({from: /"level":0/, to: /"level":0/}),
+ "Didn't find expected log line");
profileLevelDB.setProfilingLevel(1);
assert(profileLevelDB.getProfilingLevel() == 1, "p1");
+assert(profilerChangeWasLogged({from: /"level":0/, to: /"level":1/}),
+ "Didn't find expected log line");
profileLevelDB.setProfilingLevel(2);
assert(profileLevelDB.getProfilingLevel() == 2, "p2");
+assert(profilerChangeWasLogged({from: /"level":1/, to: /"level":2/}),
+ "Didn't find expected log line");
profileLevelDB.setProfilingLevel(0);
assert(profileLevelDB.getProfilingLevel() == 0, "prof level 0");
+assert(profilerChangeWasLogged({from: /"level":2/, to: /"level":0/}),
+ "Didn't find expected log line");
-var asserted = false;
-try {
+assert.throws(() => {
profileLevelDB.setProfilingLevel(10);
- assert(false);
-} catch (e) {
- asserted = true;
- assert(e.dbSetProfilingException);
-}
-assert(asserted, "should have asserted");
+});
+// Check that didn't log an invalid profile level change.
+assert(!profilerChangeWasLogged({from: /"level":0/, to: /"level":10/}), "Didn't expect log line");
})();