summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authordaveh86 <howsdav@gmail.com>2015-01-06 15:10:40 +1100
committerBenety Goh <benety@mongodb.com>2015-01-09 09:53:05 -0500
commit666b3e19b10b3ac4c3de4c7a90a7070d33154240 (patch)
tree48890b868778b4c68d83e38c505db61a480befa6 /jstests
parentecd3babf05859b9fdd29ab09fd0222a265e014f4 (diff)
downloadmongo-666b3e19b10b3ac4c3de4c7a90a7070d33154240.tar.gz
SERVER-16723 display active commands in server status only when command metrics are available.
Closes #901 Signed-off-by: Benety Goh <benety@mongodb.com>
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/opcounters_active.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/core/opcounters_active.js b/jstests/core/opcounters_active.js
new file mode 100644
index 00000000000..cf093103f47
--- /dev/null
+++ b/jstests/core/opcounters_active.js
@@ -0,0 +1,52 @@
+// checks that db.serverStatus will not throw errors when metrics tree is not present
+
+(function() {
+ "use strict";
+ //Test the getActiveCommands function
+ //Should remove the listCollections section but keep the rest
+ var testInput = {
+ "isMaster" : {
+ "failed" : NumberLong(0),
+ "total" : NumberLong(3)
+ },
+ "mapreduce" : {
+ "shardedfinish" : {
+ "failed" : NumberLong(0),
+ "total" : NumberLong(1)
+ }
+ },
+ "listCollections" : {
+ "failed" : NumberLong(0),
+ "total" : NumberLong(0)
+ }
+ };
+ var testExpected = {
+ "isMaster" : {
+ "failed" : NumberLong(0),
+ "total" : NumberLong(3)
+ },
+ "mapreduce" : {
+ "shardedfinish" : {
+ "failed" : NumberLong(0),
+ "total" : NumberLong(1)
+ }
+ }
+ };
+ var testResult = getActiveCommands(testInput);
+
+ assert.eq(testResult, testExpected, "getActiveCommands did not return the expected result");
+
+ //Test that the serverstatus helper works
+ var result = db.serverStatus();
+ assert.neq(undefined, result, result)
+ //Test that the metrics tree returns
+ assert.neq(undefined, result.metrics, result)
+ //Test that the metrics.commands tree returns
+ assert.neq(undefined, result.metrics.commands, result)
+ //Test that the metrics.commands.serverStatus value is non-zero
+ assert.neq(0, result.metrics.commands.serverStatus.total, result)
+
+ //Test that the command returns successfully when no metrics tree is present
+ var result = db.serverStatus({"metrics":0})
+ assert.eq(undefined, result.metrics, result)
+}()); \ No newline at end of file