summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/bucketauto
diff options
context:
space:
mode:
authorAlya Berciu <alyacarina@gmail.com>2021-05-21 15:24:08 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-24 15:49:05 +0000
commit441bef2c968ab24fe52d910c26dc3ecac366d0eb (patch)
treedbc5e95976ede0ce26dd4a85d0dad3a3ed582e7b /jstests/aggregation/sources/bucketauto
parent361d2c6b97d2e0c3cc80040e2cf555e68d185952 (diff)
downloadmongo-441bef2c968ab24fe52d910c26dc3ecac366d0eb.tar.gz
SERVER-57091 Fix infinite loop in GranularityRounderPreferredNumbers::roundDown
Diffstat (limited to 'jstests/aggregation/sources/bucketauto')
-rw-r--r--jstests/aggregation/sources/bucketauto/granularity_near_zero.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/bucketauto/granularity_near_zero.js b/jstests/aggregation/sources/bucketauto/granularity_near_zero.js
new file mode 100644
index 00000000000..7f456f9428d
--- /dev/null
+++ b/jstests/aggregation/sources/bucketauto/granularity_near_zero.js
@@ -0,0 +1,22 @@
+// Tests when the granularity rounder needs to approach zero to round correctly. This test was
+// designed to reproduce SERVER-57091.
+(function() {
+"use strict";
+const coll = db.server57091;
+coll.drop();
+coll.insertOne({});
+
+const res =
+ coll.aggregate([{
+ $bucketAuto: {
+ groupBy: {
+ $reduce:
+ {input: [], initialValue: 4.940656484124654e-324, in : {$size: ["$$value"]}}
+ },
+ buckets: NumberLong("8"),
+ granularity: "R80"
+ }
+ }])
+ .toArray();
+assert.eq(res, [{_id: {min: 0, max: 1.02e-321}, count: 1}]);
+})();