diff options
Diffstat (limited to 'jstests/core/top.js')
-rw-r--r-- | jstests/core/top.js | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/jstests/core/top.js b/jstests/core/top.js index 9dc1aad684e..1aff2a4136b 100644 --- a/jstests/core/top.js +++ b/jstests/core/top.js @@ -9,8 +9,8 @@ var testColl = testDB[name + "coll"]; // Ensure an empty collection exists for first top command testColl.drop(); -testColl.insert({x:0}); -testColl.remove({x:0}); +testColl.insert({x: 0}); +testColl.remove({x: 0}); // get top statistics for the test collection function getTop() { @@ -23,22 +23,24 @@ var lastTop = getTop(); // return the number of operations since the last call to diffTop for the specified key function diffTop(key) { var thisTop = getTop(); - difference = { time : thisTop[key].time - lastTop[key].time, - count : thisTop[key].count - lastTop[key].count }; + difference = { + time: thisTop[key].time - lastTop[key].time, + count: thisTop[key].count - lastTop[key].count + }; lastTop[key] = thisTop[key]; assert.gte(difference.count, 0, "non-decreasing count"); assert.gte(difference.time, 0, "non-decreasing time"); // Time should advance iff operations were performed - assert.eq(difference.count != 0, difference.time > 0,"non-zero time iff non-zero count"); + assert.eq(difference.count != 0, difference.time > 0, "non-zero time iff non-zero count"); return difference; } var numRecords = 100; // check stats for specified key are as expected -var checked = { }; +var checked = {}; function checkStats(key, expected) { checked[key]++; var actual = diffTop(key).count; @@ -46,28 +48,28 @@ function checkStats(key, expected) { } // Insert -for(i = 0; i < numRecords; i++) { - testColl.insert({_id:i}); +for (i = 0; i < numRecords; i++) { + testColl.insert({_id: i}); } checkStats("insert", numRecords); checkStats("writeLock", numRecords); // Update -for(i = 0; i < numRecords; i++) { - testColl.update({_id:i},{x:i}); +for (i = 0; i < numRecords; i++) { + testColl.update({_id: i}, {x: i}); } checkStats("update", numRecords); // Queries -var query = { }; -for(i = 0; i < numRecords; i++) { - query[i] = testColl.find({x : {$gte:i}}).batchSize(2); +var query = {}; +for (i = 0; i < numRecords; i++) { + query[i] = testColl.find({x: {$gte: i}}).batchSize(2); assert.eq(query[i].next()._id, i); } -checkStats("queries" ,numRecords); +checkStats("queries", numRecords); // Getmore -for(i = 0; i < numRecords / 2; i++) { +for (i = 0; i < numRecords / 2; i++) { assert.eq(query[i].next()._id, i + 1); assert.eq(query[i].next()._id, i + 2); assert.eq(query[i].next()._id, i + 3); @@ -76,28 +78,26 @@ for(i = 0; i < numRecords / 2; i++) { checkStats("getmore", numRecords); // Remove -for(i = 0; i < numRecords; i++) { - testColl.remove({_id : 1}); +for (i = 0; i < numRecords; i++) { + testColl.remove({_id: 1}); } checkStats("remove", numRecords); // Upsert, note that these are counted as updates, not inserts -for(i = 0; i < numRecords; i++) { - testColl.update({_id:i},{x:i},{upsert:1}); +for (i = 0; i < numRecords; i++) { + testColl.update({_id: i}, {x: i}, {upsert: 1}); } checkStats("update", numRecords); - // Commands -diffTop("commands"); // ignore any commands before this -for(i = 0; i < numRecords; i++) { - assert.eq(testDB.runCommand({count:"toptestcoll"}).n, numRecords); +diffTop("commands"); // ignore any commands before this +for (i = 0; i < numRecords; i++) { + assert.eq(testDB.runCommand({count: "toptestcoll"}).n, numRecords); } checkStats("commands", numRecords); -for(key in lastTop) { - if (!(key in checked)) { - printjson({key:key, stats:diffTop(key)}); - } +for (key in lastTop) { + if (!(key in checked)) { + printjson({key: key, stats: diffTop(key)}); + } } - |