diff options
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/auth/lib/commands_lib.js | 20 | ||||
-rw-r--r-- | jstests/core/profile_sampling.js | 51 | ||||
-rw-r--r-- | jstests/libs/parallelTester.js | 1 |
3 files changed, 72 insertions, 0 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index 3cbf3dfcc9b..29b6eb4a669 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -3586,6 +3586,26 @@ var authCommandsLib = { ] }, { + testname: "profileSetSampleRate", + command: {profile: -1, sampleRate: 0.5}, + skipSharded: true, + testcases: [ + { + runOnDb: firstDbName, + roles: roles_dbAdmin, + privileges: + [{resource: {db: firstDbName, collection: ""}, actions: ["enableProfiler"]}] + }, + { + runOnDb: secondDbName, + roles: roles_dbAdminAny, + privileges: [ + {resource: {db: secondDbName, collection: ""}, actions: ["enableProfiler"]} + ] + } + ] + }, + { testname: "renameCollection_sameDb", command: {renameCollection: firstDbName + ".x", to: firstDbName + ".y", dropTarget: true}, setup: function(db) { diff --git a/jstests/core/profile_sampling.js b/jstests/core/profile_sampling.js new file mode 100644 index 00000000000..6ad60060845 --- /dev/null +++ b/jstests/core/profile_sampling.js @@ -0,0 +1,51 @@ +// Confirms that the number of profiled operations is consistent with the sampleRate, if set. +(function() { + "use strict"; + + // Use a special db to support running other tests in parallel. + var profileDB = db.getSisterDB("profile_sampling"); + var coll = profileDB.profile_sampling; + + profileDB.dropDatabase(); + + var originalProfilingSettings; + try { + originalProfilingSettings = assert.commandWorked(profileDB.setProfilingLevel(0)); + profileDB.system.profile.drop(); + assert.eq(0, profileDB.system.profile.count()); + + profileDB.createCollection(coll.getName()); + assert.writeOK(coll.insert({x: 1})); + + assert.commandWorked(profileDB.setProfilingLevel(2, {sampleRate: 0})); + + assert.neq(null, coll.findOne({x: 1})); + assert.eq(1, coll.find({x: 1}).count()); + assert.writeOK(coll.update({x: 1}, {$inc: {a: 1}})); + + profileDB.setProfilingLevel(0); + + profileDB.system.profile.find().forEach(printjson); + assert.eq(0, profileDB.system.profile.count()); + + profileDB.system.profile.drop(); + assert.commandWorked(profileDB.setProfilingLevel(2, {sampleRate: 0.5})); + + // This should generate about 500 profile log entries. + for (var i = 0; i < 500; i++) { + assert.neq(null, coll.findOne({x: 1})); + assert.writeOK(coll.update({x: 1}, {$inc: {a: 1}})); + } + + profileDB.setProfilingLevel(0); + + assert.between(10, profileDB.system.profile.count(), 990); + } finally { + let profileCmd = {}; + profileCmd.profile = originalProfilingSettings.was; + profileCmd = Object.extend(profileCmd, originalProfilingSettings); + delete profileCmd.was; + delete profileCmd.ok; + assert.commandWorked(profileDB.runCommand(profileCmd)); + } +}()); diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index 21d44b3f813..418b06b5d12 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -247,6 +247,7 @@ if (typeof _threadInject != "undefined") { parallelFilesDir + "/profile_insert.js", parallelFilesDir + "/profile_mapreduce.js", parallelFilesDir + "/profile_no_such_db.js", + parallelFilesDir + "/profile_sampling.js", parallelFilesDir + "/profile_update.js" ]; var serialTests = makeKeys(serialTestsArr); |