summaryrefslogtreecommitdiff
path: root/jstests/core/administrative/profile/profile_no_such_db.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/administrative/profile/profile_no_such_db.js')
-rw-r--r--jstests/core/administrative/profile/profile_no_such_db.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/jstests/core/administrative/profile/profile_no_such_db.js b/jstests/core/administrative/profile/profile_no_such_db.js
new file mode 100644
index 00000000000..141be56b201
--- /dev/null
+++ b/jstests/core/administrative/profile/profile_no_such_db.js
@@ -0,0 +1,41 @@
+// The test runs commands that are not allowed with security token: setProfilingLevel.
+// @tags: [
+// not_allowed_with_security_token,does_not_support_stepdowns, requires_profiling]
+
+// Test that reading the profiling level doesn't create databases, but setting it does.
+(function(db) {
+'use strict';
+
+function dbExists() {
+ return Array.contains(db.getMongo().getDBNames(), db.getName());
+}
+
+db = db.getSiblingDB('profile_no_such_db'); // Note: changes db argument not global var.
+assert.commandWorked(db.dropDatabase());
+assert(!dbExists());
+
+// Reading the profiling level shouldn't create the database.
+var defaultProfilingLevel = db.getProfilingLevel();
+assert(!dbExists());
+
+// This test assumes that the default profiling level hasn't been changed.
+assert.eq(defaultProfilingLevel, 0);
+
+[0, 1, 2].forEach(function(level) {
+ jsTest.log('Testing profiling level ' + level);
+
+ // Setting the profiling level creates the database.
+ // Note: setting the profiling level to 0 puts the database in a weird state where it
+ // exists internally, but doesn't show up in listDatabases, and won't exist if you
+ // restart the server.
+ var res = db.setProfilingLevel(level);
+ assert.eq(res.was, defaultProfilingLevel);
+ assert(dbExists() || level == 0);
+ assert.eq(db.getProfilingLevel(), level);
+
+ // Dropping the db reverts the profiling level to the default.
+ assert.commandWorked(db.dropDatabase());
+ assert.eq(db.getProfilingLevel(), defaultProfilingLevel);
+ assert(!dbExists());
+});
+}(db));