summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDenis Grebennicov <denis.grebennicov@mongodb.com>2021-04-16 11:28:00 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-28 16:54:14 +0000
commitbf5ff3ee53d1c85f5bc039735945a6a0cb512a93 (patch)
treef12ddd6e5afe56108b3948011f2c7f2788025771 /jstests
parent43941b42e08c6e7b8e5928cc4e6f94ace7667d74 (diff)
downloadmongo-bf5ff3ee53d1c85f5bc039735945a6a0cb512a93.tar.gz
SERVER-51072 $skip and $limit stages silently round large doubles to MAX_LONG
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/bugs/skip_limit_overflow.js16
-rw-r--r--jstests/aggregation/sources/match/skip_with_limit.js23
2 files changed, 23 insertions, 16 deletions
diff --git a/jstests/aggregation/bugs/skip_limit_overflow.js b/jstests/aggregation/bugs/skip_limit_overflow.js
index 6d1cbd15482..2ca22a0c3e5 100644
--- a/jstests/aggregation/bugs/skip_limit_overflow.js
+++ b/jstests/aggregation/bugs/skip_limit_overflow.js
@@ -62,22 +62,6 @@ function testPipeline(pipeline, expectedResult, optimizedAwayStages) {
assert.eq(coll.aggregate(pipeline).toArray(), []);
}
-// Case where overflow of limit + skip prevents limit stage from being absorbed. Values are
-// specified as integrals > MAX_LONG. Note that we cannot specify this huge value as a NumberLong,
-// as we get a number conversion error (even if it's passed as a string).
-testPipeline([{$sort: {x: -1}}, {$skip: 18446744073709552000}, {$limit: 6}],
- {
- $limit: {path: "$limit", expectedValue: [NumberLong(6)]},
- SKIP: {path: "skipAmount", expectedValue: [NumberLong("9223372036854775807")]}
- },
- ["$skip"]);
-testPipeline([{$sort: {x: -1}}, {$skip: 6}, {$limit: 18446744073709552000}],
- {
- $limit: {path: "$limit", expectedValue: [NumberLong("9223372036854775807")]},
- SKIP: {path: "skipAmount", expectedValue: [6]}
- },
- ["$skip"]);
-
// Case where overflow of limit + skip prevents limit stage from being absorbed. One of the
// values == MAX_LONG, another one is 1.
testPipeline([{$sort: {x: -1}}, {$skip: NumberLong("9223372036854775807")}, {$limit: 1}],
diff --git a/jstests/aggregation/sources/match/skip_with_limit.js b/jstests/aggregation/sources/match/skip_with_limit.js
index 71651b13f3e..d662ddf2d80 100644
--- a/jstests/aggregation/sources/match/skip_with_limit.js
+++ b/jstests/aggregation/sources/match/skip_with_limit.js
@@ -124,4 +124,27 @@ count = coll.aggregate([
])
.itcount();
assert.eq(count, 3);
+
+function assertAggregateCommandFailed(pipeline, expectedErrorCode) {
+ const err = assert.throws(() => coll.aggregate(pipeline));
+ assert.commandFailedWithCode(err, expectedErrorCode);
+}
+
+// Verifies that command fails executing when $skip argument is greater than MAX_LONG.
+assertAggregateCommandFailed([{$skip: 18446744073709552000}], 5107200);
+
+// Verifies that command fails executing when $limit argument is greater than MAX_LONG.
+assertAggregateCommandFailed([{$limit: 18446744073709552000}], 5107201);
+
+// Verifies that command fails executing when $skip argument is negative.
+assertAggregateCommandFailed([{$skip: -1}], 5107200);
+
+// Verifies that command fails executing when $limit argument is negative.
+assertAggregateCommandFailed([{$limit: -1}], 5107201);
+
+// Verifies that command succeeds when $skip argument is zero.
+assert.eq(coll.aggregate([{$skip: 0}]).itcount(), 20);
+
+// Verifies that command fails executing when $limit argument is zero.
+assertAggregateCommandFailed([{$limit: 0}], 15958);
}());