summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp b/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp
index 4f89e47acdf..262806e0780 100644
--- a/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp
+++ b/src/mongo/db/pipeline/document_source_plan_cache_stats_test.cpp
@@ -41,6 +41,8 @@ namespace mongo {
using DocumentSourcePlanCacheStatsTest = AggregationContextFixture;
+static const SerializationOptions kExplain =
+ SerializationOptions{boost::make_optional(ExplainOptions::Verbosity::kQueryPlanner)};
/**
* A MongoProcessInterface used for testing which returns artificial plan cache stats.
*/
@@ -106,7 +108,9 @@ TEST_F(DocumentSourcePlanCacheStatsTest, CanParseAndSerializeAsExplainSuccessful
const auto specObj = fromjson("{$planCacheStats: {}}");
auto stage = DocumentSourcePlanCacheStats::createFromBson(specObj.firstElement(), getExpCtx());
std::vector<Value> serialized;
- stage->serializeToArray(serialized, ExplainOptions::Verbosity::kQueryPlanner);
+ stage->serializeToArray(
+ serialized,
+ SerializationOptions{boost::make_optional(ExplainOptions::Verbosity::kQueryPlanner)});
ASSERT_EQ(1u, serialized.size());
ASSERT_BSONOBJ_EQ(specObj, serialized[0].getDocument().toBson());
}
@@ -139,12 +143,31 @@ TEST_F(DocumentSourcePlanCacheStatsTest, SerializesSuccessfullyAfterAbsorbingMat
pipeline->optimizePipeline();
ASSERT_EQ(1u, pipeline->getSources().size());
- auto serialized = pipeline->writeExplainOps(ExplainOptions::Verbosity::kQueryPlanner);
+ auto serialized = pipeline->writeExplainOps(kExplain);
ASSERT_EQ(1u, serialized.size());
ASSERT_BSONOBJ_EQ(fromjson("{$planCacheStats: {match: {foo: 'bar'}}}"),
serialized[0].getDocument().toBson());
}
+TEST_F(DocumentSourcePlanCacheStatsTest, RedactsSuccessfullyAfterAbsorbingMatch) {
+ const auto specObj = fromjson("{$planCacheStats: {}}");
+ auto planCacheStats =
+ DocumentSourcePlanCacheStats::createFromBson(specObj.firstElement(), getExpCtx());
+ auto match = DocumentSourceMatch::create(fromjson("{foo: 'bar'}"), getExpCtx());
+ auto pipeline = Pipeline::create({planCacheStats, match}, getExpCtx());
+ ASSERT_EQ(2u, pipeline->getSources().size());
+
+ pipeline->optimizePipeline();
+ ASSERT_EQ(1u, pipeline->getSources().size());
+ auto serialized = redactToArray(*pipeline->getSources().front());
+ ASSERT_EQ(2u, serialized.size());
+
+ ASSERT_BSONOBJ_EQ(specObj, serialized[0].getDocument().toBson());
+ ASSERT_BSONOBJ_EQ_AUTO( // NOLINT
+ R"({"$match":{"HASH<foo>":{"$eq":"?string"}}})",
+ serialized[1].getDocument().toBson().getOwned());
+}
+
TEST_F(DocumentSourcePlanCacheStatsTest, ReturnsImmediateEOFWithEmptyPlanCache) {
getExpCtx()->mongoProcessInterface =
std::make_shared<PlanCacheStatsMongoProcessInterface>(std::vector<BSONObj>{});