summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Fefer <ivan.fefer@mongodb.com>2022-11-18 13:37:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-18 14:34:43 +0000
commitb6492f51903fd7ddbae2b0df165f03927aff4d81 (patch)
tree95f736de484d32950c6fd68e5f24fa7c7e4fbd34 /src
parent0cc9b3c18908e59e630ff70eb1458b47174763d5 (diff)
downloadmongo-b6492f51903fd7ddbae2b0df165f03927aff4d81.tar.gz
SERVER-70267 Fix asan failure in DocumentSourceGroupTests unit tests
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/pipeline/document_source_group_test.cpp55
1 files changed, 17 insertions, 38 deletions
diff --git a/src/mongo/db/pipeline/document_source_group_test.cpp b/src/mongo/db/pipeline/document_source_group_test.cpp
index ef29cdb2795..9c8a800caae 100644
--- a/src/mongo/db/pipeline/document_source_group_test.cpp
+++ b/src/mongo/db/pipeline/document_source_group_test.cpp
@@ -966,17 +966,11 @@ private:
}
BSONObj groupSpec() final {
- BSONObjBuilder builder;
- builder.append("_id", "$a");
- BSONObjBuilder accum(builder.subobjStart("big_array"));
- accum.append("$push", "$b");
- accum.done();
-
if constexpr (groupStageType == GroupStageType::Streaming) {
- BSONArrayBuilder sub(builder.subarrayStart("$monotonicIdFields"));
- sub.append("_id").done();
+ return fromjson("{_id: '$a', big_array: {$push: '$b'}, $monotonicIdFields: ['_id']}");
+ } else {
+ return fromjson("{_id: '$a', big_array: {$push: '$b'}}");
}
- return builder.done();
}
boost::optional<size_t> getMaxMemoryUsageBytes() final {
@@ -986,7 +980,7 @@ private:
BSONObj expectedResultSet() final {
BSONArrayBuilder result;
for (int i = 0; i < kCount; ++i) {
- result.append(BSON("_id" << i << "big_array" << BSON_ARRAY(kBigString)));
+ result << BSON("_id" << i << "big_array" << BSON_ARRAY(kBigString));
}
return result.arr();
}
@@ -1031,9 +1025,9 @@ private:
BSONArrayBuilder result;
for (int i = 0; i < kCount; ++i) {
auto id = BSON("x" << 0 << "y" << i);
- result.append(BSON("_id" << id << "big_array" << BSON_ARRAY(kBigString)));
+ result << BSON("_id" << id << "big_array" << BSON_ARRAY(kBigString));
}
- return result.done();
+ return result.arr();
}
};
@@ -1073,13 +1067,13 @@ private:
BSONObj expectedResultSet() final {
BSONArrayBuilder result;
for (int i = 0; i < kCount; ++i) {
- BSONArrayBuilder bigArray;
+ BSONArrayBuilder bigArrayBuilder;
for (int j = 0; j < (i % 3) + 1; ++j) {
- bigArray.append(kBigString);
+ bigArrayBuilder << kBigString;
}
- result.append(BSON("_id" << i << "big_array" << bigArray.arr()));
+ result << BSON("_id" << i << "big_array" << bigArrayBuilder.arr());
}
- return result.done();
+ return result.arr();
}
};
@@ -1121,8 +1115,8 @@ private:
BSONArrayBuilder result;
for (int i = 0; i < kCount; ++i) {
for (int j = 0; j < kCount; ++j) {
- result.append(BSON("_id" << BSON("x" << i << "y" << j) << "sum"
- << (kCount * (kCount - 1)) / 2));
+ result << BSON("_id" << BSON("x" << i << "y" << j) << "sum"
+ << (kCount * (kCount - 1)) / 2);
}
}
return result.arr();
@@ -1146,18 +1140,8 @@ private:
}
BSONObj groupSpec() final {
- BSONObjBuilder builder;
-
- BSONObjBuilder id(builder.subobjStart("_id"));
- id.append("x", "$x").append("y", "$y").done();
-
- BSONObjBuilder accum(builder.subobjStart("sum"));
- accum.append("$sum", "$z").done();
-
- BSONArrayBuilder sub(builder.subarrayStart("$monotonicIdFields"));
- sub.append("x").append("y").done();
-
- return builder.done();
+ return fromjson(
+ "{_id: {x: '$x', y: '$y'}, sum: {$sum: '$z'}, $monotonicIdFields: ['x', 'y']}");
}
boost::optional<size_t> getMaxMemoryUsageBytes() final {
@@ -1166,14 +1150,9 @@ private:
BSONObj expectedResultSet() final {
BSONArrayBuilder result;
- generateInputOutput([&result](int x, int y) {
- BSONObjBuilder builder(result.subobjStart());
-
- BSONObjBuilder id(builder.subobjStart("_id"));
- id.append("x", x).append("y", y).done();
-
- builder.append("sum", (kCount * (kCount - 1)) / 2);
- builder.done();
+ const int sum = (kCount * (kCount - 1)) / 2;
+ generateInputOutput([&](int x, int y) {
+ result << BSON("_id" << BSON("x" << x << "y" << y) << "sum" << sum);
});
return result.arr();
}