summaryrefslogtreecommitdiff
path: root/jstests/core/max_time_ms.js
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:17:50 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:18:14 -0500
commit4ae691e8edc87d0e3cfb633bb91c328426be007b (patch)
tree52079a593f54382ca13a2e741633eab1b6271893 /jstests/core/max_time_ms.js
parenta025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff)
downloadmongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/core/max_time_ms.js')
-rw-r--r--jstests/core/max_time_ms.js365
1 files changed, 224 insertions, 141 deletions
diff --git a/jstests/core/max_time_ms.js b/jstests/core/max_time_ms.js
index 9c2797ca12b..e70ae8cb0fe 100644
--- a/jstests/core/max_time_ms.js
+++ b/jstests/core/max_time_ms.js
@@ -1,7 +1,7 @@
// Tests query/command option $maxTimeMS.
var t = db.max_time_ms;
-var exceededTimeLimit = 50; // ErrorCodes::ExceededTimeLimit
+var exceededTimeLimit = 50; // ErrorCodes::ExceededTimeLimit
var cursor;
var res;
@@ -10,10 +10,17 @@ var res;
//
t.drop();
-t.insert([{},{},{}]);
-cursor = t.find({$where: function() { sleep(100); return true; }});
+t.insert([{}, {}, {}]);
+cursor = t.find({
+ $where: function() {
+ sleep(100);
+ return true;
+ }
+});
cursor.maxTimeMS(100);
-assert.throws(function() { cursor.itcount(); }, [], "expected query to abort due to time limit");
+assert.throws(function() {
+ cursor.itcount();
+}, [], "expected query to abort due to time limit");
//
// Simple negative test for query: a ~300ms query with a 10s time limit should not hit the time
@@ -21,12 +28,17 @@ assert.throws(function() { cursor.itcount(); }, [], "expected query to abort due
//
t.drop();
-t.insert([{},{},{}]);
-cursor = t.find({$where: function() { sleep(100); return true; }});
-cursor.maxTimeMS(10*1000);
-assert.doesNotThrow(function() { cursor.itcount(); },
- [],
- "expected query to not hit the time limit");
+t.insert([{}, {}, {}]);
+cursor = t.find({
+ $where: function() {
+ sleep(100);
+ return true;
+ }
+});
+cursor.maxTimeMS(10 * 1000);
+assert.doesNotThrow(function() {
+ cursor.itcount();
+}, [], "expected query to not hit the time limit");
//
// Simple positive test for getmore:
@@ -36,22 +48,28 @@ assert.doesNotThrow(function() { cursor.itcount(); },
//
t.drop();
-t.insert([{},{},{}]); // fast batch
-t.insert([{slow: true},{slow: true},{slow: true}]); // slow batch
-cursor = t.find({$where: function() {
- if (this.slow) {
- sleep(5*1000);
+t.insert([{}, {}, {}]); // fast batch
+t.insert([{slow: true}, {slow: true}, {slow: true}]); // slow batch
+cursor = t.find({
+ $where: function() {
+ if (this.slow) {
+ sleep(5 * 1000);
+ }
+ return true;
}
- return true;
-}});
+});
cursor.batchSize(3);
cursor.maxTimeMS(1000);
-assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 1 (query) to not hit the time limit");
-assert.throws(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 2 (getmore) to abort due to time limit");
+assert.doesNotThrow(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 1 (query) to not hit the time limit");
+assert.throws(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 2 (getmore) to abort due to time limit");
//
// Simple negative test for getmore:
@@ -61,22 +79,28 @@ assert.throws(function() { cursor.next(); cursor.next(); cursor.next(); },
//
t.drop();
-t.insert([{},{},{}]); // fast batch
-t.insert([{},{},{slow: true}]); // slow batch
-cursor = t.find({$where: function() {
- if (this.slow) {
- sleep(2*1000);
+t.insert([{}, {}, {}]); // fast batch
+t.insert([{}, {}, {slow: true}]); // slow batch
+cursor = t.find({
+ $where: function() {
+ if (this.slow) {
+ sleep(2 * 1000);
+ }
+ return true;
}
- return true;
-}});
+});
cursor.batchSize(3);
-cursor.maxTimeMS(10*1000);
-assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 1 (query) to not hit the time limit");
-assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 2 (getmore) to not hit the time limit");
+cursor.maxTimeMS(10 * 1000);
+assert.doesNotThrow(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 1 (query) to not hit the time limit");
+assert.doesNotThrow(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 2 (getmore) to not hit the time limit");
//
// Many-batch positive test for getmore:
@@ -85,18 +109,22 @@ assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
//
t.drop();
-for (var i=0; i<5; i++) {
- t.insert([{},{},{slow:true}]);
+for (var i = 0; i < 5; i++) {
+ t.insert([{}, {}, {slow: true}]);
}
-cursor = t.find({$where: function() {
- if (this.slow) {
- sleep(2*1000);
+cursor = t.find({
+ $where: function() {
+ if (this.slow) {
+ sleep(2 * 1000);
+ }
+ return true;
}
- return true;
-}});
+});
cursor.batchSize(3);
-cursor.maxTimeMS(6*1000);
-assert.throws(function() { cursor.itcount(); }, [], "expected find() to abort due to time limit");
+cursor.maxTimeMS(6 * 1000);
+assert.throws(function() {
+ cursor.itcount();
+}, [], "expected find() to abort due to time limit");
//
// Many-batch negative test for getmore:
@@ -105,20 +133,22 @@ assert.throws(function() { cursor.itcount(); }, [], "expected find() to abort du
//
t.drop();
-for (var i=0; i<5; i++) {
- t.insert([{},{},{slow:true}]);
+for (var i = 0; i < 5; i++) {
+ t.insert([{}, {}, {slow: true}]);
}
-cursor = t.find({$where: function() {
- if (this.slow) {
- sleep(2*1000);
+cursor = t.find({
+ $where: function() {
+ if (this.slow) {
+ sleep(2 * 1000);
+ }
+ return true;
}
- return true;
-}});
+});
cursor.batchSize(3);
-cursor.maxTimeMS(20*1000);
-assert.doesNotThrow(function() { cursor.itcount(); },
- [],
- "expected find() to not hit the time limit");
+cursor.maxTimeMS(20 * 1000);
+assert.doesNotThrow(function() {
+ cursor.itcount();
+}, [], "expected find() to not hit the time limit");
//
// Simple positive test for commands: a ~300ms command with a 100ms time limit should be aborted.
@@ -135,7 +165,7 @@ assert(res.ok == 0 && res.code == exceededTimeLimit,
//
t.drop();
-res = t.getDB().adminCommand({sleep: 1, millis: 300, maxTimeMS: 10*1000});
+res = t.getDB().adminCommand({sleep: 1, millis: 300, maxTimeMS: 10 * 1000});
assert(res.ok == 1,
"expected sleep command to not hit the time limit, ok=" + res.ok + ", code=" + res.code);
@@ -148,45 +178,81 @@ t.insert({});
// Verify lower boundary for acceptable input (0 is acceptable, 1 isn't).
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(0).itcount(); });
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(NumberInt(0)).itcount(); });
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(NumberLong(0)).itcount(); });
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(0).itcount();
+});
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(NumberInt(0)).itcount();
+});
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(NumberLong(0)).itcount();
+});
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: 0}).ok);
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: NumberInt(0)}).ok);
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: NumberLong(0)}).ok);
-assert.throws.automsg(function() { t.find().maxTimeMS(-1).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(NumberInt(-1)).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(NumberLong(-1)).itcount(); });
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(-1).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(NumberInt(-1)).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(NumberLong(-1)).itcount();
+});
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: -1}).ok);
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberInt(-1)}).ok);
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberLong(-1)}).ok);
// Verify upper boundary for acceptable input (2^31-1 is acceptable, 2^31 isn't).
-var maxValue = Math.pow(2,31)-1;
+var maxValue = Math.pow(2, 31) - 1;
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(maxValue).itcount(); });
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(NumberInt(maxValue)).itcount(); });
-assert.doesNotThrow.automsg(function() { t.find().maxTimeMS(NumberLong(maxValue)).itcount(); });
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(maxValue).itcount();
+});
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(NumberInt(maxValue)).itcount();
+});
+assert.doesNotThrow.automsg(function() {
+ t.find().maxTimeMS(NumberLong(maxValue)).itcount();
+});
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: maxValue}).ok);
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: NumberInt(maxValue)}).ok);
assert.eq(1, t.getDB().runCommand({ping: 1, maxTimeMS: NumberLong(maxValue)}).ok);
-assert.throws.automsg(function() { t.find().maxTimeMS(maxValue+1).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(NumberInt(maxValue+1)).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(NumberLong(maxValue+1)).itcount(); });
-assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: maxValue+1}).ok);
-assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberInt(maxValue+1)}).ok);
-assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberLong(maxValue+1)}).ok);
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(maxValue + 1).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(NumberInt(maxValue + 1)).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(NumberLong(maxValue + 1)).itcount();
+});
+assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: maxValue + 1}).ok);
+assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberInt(maxValue + 1)}).ok);
+assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: NumberLong(maxValue + 1)}).ok);
// Verify invalid values are rejected.
-assert.throws.automsg(function() { t.find().maxTimeMS(0.1).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(-0.1).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS().itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS("").itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS(true).itcount(); });
-assert.throws.automsg(function() { t.find().maxTimeMS({}).itcount(); });
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(0.1).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(-0.1).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS().itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS("").itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS(true).itcount();
+});
+assert.throws.automsg(function() {
+ t.find().maxTimeMS({}).itcount();
+});
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: 0.1}).ok);
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: -0.1}).ok);
assert.eq(0, t.getDB().runCommand({ping: 1, maxTimeMS: undefined}).ok);
@@ -210,9 +276,9 @@ assert.eq(0, cursor.next().ok);
// TODO: rewrite to use runCommandWithMetadata when we have a shell helper so that
// we can test server side validation.
assert.throws(function() {
- cursor = t.getDB().$cmd.find({ping: 1}).limit(-1).maxTimeMS(0);
- cursor._ensureSpecial();
- cursor.next();
+ cursor = t.getDB().$cmd.find({ping: 1}).limit(-1).maxTimeMS(0);
+ cursor._ensureSpecial();
+ cursor.next();
});
//
@@ -221,77 +287,91 @@ assert.throws(function() {
// maxTimeAlwaysTimeOut positive test for command.
t.drop();
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut",
- mode: "alwaysOn"}).ok);
-res = t.getDB().runCommand({ping: 1, maxTimeMS: 10*1000});
+assert.eq(
+ 1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "alwaysOn"}).ok);
+res = t.getDB().runCommand({ping: 1, maxTimeMS: 10 * 1000});
assert(res.ok == 0 && res.code == exceededTimeLimit,
- "expected command to trigger maxTimeAlwaysTimeOut fail point, ok=" + res.ok + ", code="
- + res.code);
+ "expected command to trigger maxTimeAlwaysTimeOut fail point, ok=" + res.ok + ", code=" +
+ res.code);
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok);
// maxTimeNeverTimeOut positive test for command.
t.drop();
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut",
- mode: "alwaysOn"}).ok);
+assert.eq(1,
+ t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "alwaysOn"}).ok);
res = t.getDB().adminCommand({sleep: 1, millis: 300, maxTimeMS: 100});
assert(res.ok == 1,
- "expected command to trigger maxTimeNeverTimeOut fail point, ok=" + res.ok + ", code="
- + res.code);
+ "expected command to trigger maxTimeNeverTimeOut fail point, ok=" + res.ok + ", code=" +
+ res.code);
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "off"}).ok);
// maxTimeAlwaysTimeOut positive test for query.
t.drop();
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut",
- mode: "alwaysOn"}).ok);
-assert.throws(function() { t.find().maxTimeMS(10*1000).itcount(); },
- [],
- "expected query to trigger maxTimeAlwaysTimeOut fail point");
+assert.eq(
+ 1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "alwaysOn"}).ok);
+assert.throws(function() {
+ t.find().maxTimeMS(10 * 1000).itcount();
+}, [], "expected query to trigger maxTimeAlwaysTimeOut fail point");
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok);
// maxTimeNeverTimeOut positive test for query.
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut",
- mode: "alwaysOn"}).ok);
+assert.eq(1,
+ t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "alwaysOn"}).ok);
t.drop();
-t.insert([{},{},{}]);
-cursor = t.find({$where: function() { sleep(100); return true; }});
+t.insert([{}, {}, {}]);
+cursor = t.find({
+ $where: function() {
+ sleep(100);
+ return true;
+ }
+});
cursor.maxTimeMS(100);
-assert.doesNotThrow(function() { cursor.itcount(); },
- [],
- "expected query to trigger maxTimeNeverTimeOut fail point");
+assert.doesNotThrow(function() {
+ cursor.itcount();
+}, [], "expected query to trigger maxTimeNeverTimeOut fail point");
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "off"}).ok);
// maxTimeAlwaysTimeOut positive test for getmore.
t.drop();
-t.insert([{},{},{}]);
-cursor = t.find().maxTimeMS(10*1000).batchSize(2);
-assert.doesNotThrow.automsg(function() { cursor.next(); cursor.next(); });
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut",
- mode: "alwaysOn"}).ok);
-assert.throws(function() { cursor.next(); },
- [],
- "expected getmore to trigger maxTimeAlwaysTimeOut fail point");
+t.insert([{}, {}, {}]);
+cursor = t.find().maxTimeMS(10 * 1000).batchSize(2);
+assert.doesNotThrow.automsg(function() {
+ cursor.next();
+ cursor.next();
+});
+assert.eq(
+ 1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "alwaysOn"}).ok);
+assert.throws(function() {
+ cursor.next();
+}, [], "expected getmore to trigger maxTimeAlwaysTimeOut fail point");
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}).ok);
// maxTimeNeverTimeOut positive test for getmore.
t.drop();
-t.insert([{},{},{}]); // fast batch
-t.insert([{slow: true},{slow: true},{slow: true}]); // slow batch
-cursor = t.find({$where: function() {
- if (this.slow) {
- sleep(2*1000);
+t.insert([{}, {}, {}]); // fast batch
+t.insert([{slow: true}, {slow: true}, {slow: true}]); // slow batch
+cursor = t.find({
+ $where: function() {
+ if (this.slow) {
+ sleep(2 * 1000);
+ }
+ return true;
}
- return true;
-}});
+});
cursor.batchSize(3);
-cursor.maxTimeMS(2*1000);
-assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 1 (query) to not hit the time limit");
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut",
- mode: "alwaysOn"}).ok);
-assert.doesNotThrow(function() { cursor.next(); cursor.next(); cursor.next(); },
- [],
- "expected batch 2 (getmore) to trigger maxTimeNeverTimeOut fail point");
+cursor.maxTimeMS(2 * 1000);
+assert.doesNotThrow(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 1 (query) to not hit the time limit");
+assert.eq(1,
+ t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "alwaysOn"}).ok);
+assert.doesNotThrow(function() {
+ cursor.next();
+ cursor.next();
+ cursor.next();
+}, [], "expected batch 2 (getmore) to trigger maxTimeNeverTimeOut fail point");
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "off"}).ok);
//
@@ -299,33 +379,36 @@ assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut",
//
// "aggregate" command.
-res = t.runCommand("aggregate", {pipeline: [], maxTimeMS: 60*1000});
+res = t.runCommand("aggregate", {pipeline: [], maxTimeMS: 60 * 1000});
assert(res.ok == 1,
"expected aggregate with maxtime to succeed, ok=" + res.ok + ", code=" + res.code);
// "collMod" command.
-res = t.runCommand("collMod", {usePowerOf2Sizes: true, maxTimeMS: 60*1000});
+res = t.runCommand("collMod", {usePowerOf2Sizes: true, maxTimeMS: 60 * 1000});
assert(res.ok == 1,
"expected collmod with maxtime to succeed, ok=" + res.ok + ", code=" + res.code);
//
// Test maxTimeMS for parallelCollectionScan
//
-res = t.runCommand({parallelCollectionScan: t.getName(), numCursors: 1, maxTimeMS: 60*1000});
+res = t.runCommand({parallelCollectionScan: t.getName(), numCursors: 1, maxTimeMS: 60 * 1000});
assert.commandWorked(res);
-var cursor = new DBCommandCursor( t.getDB().getMongo(), res.cursors[0], 5 );
-assert.commandWorked(t.getDB().adminCommand({
- configureFailPoint: "maxTimeAlwaysTimeOut",
- mode: "alwaysOn"
-}));
-assert.throws(function() { cursor.itcount(); }, [], "expected query to abort due to time limit");
-assert.commandWorked(t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}));
+var cursor = new DBCommandCursor(t.getDB().getMongo(), res.cursors[0], 5);
+assert.commandWorked(
+ t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "alwaysOn"}));
+assert.throws(function() {
+ cursor.itcount();
+}, [], "expected query to abort due to time limit");
+assert.commandWorked(
+ t.getDB().adminCommand({configureFailPoint: "maxTimeAlwaysTimeOut", mode: "off"}));
//
// test count shell helper SERVER-13334
//
t.drop();
-assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut",
- mode: "alwaysOn"}).ok);
-assert.doesNotThrow(function() { t.find({}).maxTimeMS(1).count(); });
+assert.eq(1,
+ t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "alwaysOn"}).ok);
+assert.doesNotThrow(function() {
+ t.find({}).maxTimeMS(1).count();
+});
assert.eq(1, t.getDB().adminCommand({configureFailPoint: "maxTimeNeverTimeOut", mode: "off"}).ok);