summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_lookup_test.cpp
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2018-06-22 12:00:21 -0400
committerAndy Schwerin <schwerin@mongodb.com>2018-06-22 12:32:29 -0400
commitd520be0814492c262515cf0a5d62a127ace70dce (patch)
treee754e3cce243a7b51922b6d2a179a3d355ccefb7 /src/mongo/db/pipeline/document_source_lookup_test.cpp
parentc0b942e3a80b9ccd8434ab0927d97cbd1862d19a (diff)
downloadmongo-d520be0814492c262515cf0a5d62a127ace70dce.tar.gz
SERVER-34798 Remove ServiceContext subclasses and use new ServiceContext in every unit test.
This patch does several loosely related and surprisingly hard to separate things. 1.) Make the ServiceContext class final 2.) Create a mechanism, called ConstructorActions, for running methods on ServiceContexts immediately after they're built and immediately before they're destroyed. 3.) Introduce / improve test fixture base classes for tests, giving them fresh ServiceContext instances for each test case. There is one fixture for tests that need a storage engine and another for those that do not. 4.) Make several remaining global variables SC decorations in support of (3) 5.) Replace many MONGO_INITIALIZERS that access getGlobalServiceContext with the new constructor-actions system, which is needed for (3.) 6.) Fix up tests to use the fixtures from (3) and fix tests that silently used different service contexts in together in a technically illegal fashion that now breaks. 7.) Utilize (2) as necessary to simplify initialization of new ServiceContexts, simplifying the fixtures in (3).
Diffstat (limited to 'src/mongo/db/pipeline/document_source_lookup_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_test.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp
index 3c27f9a90ab..00c0baeecdb 100644
--- a/src/mongo/db/pipeline/document_source_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp
@@ -85,7 +85,7 @@ public:
TEST_F(DocumentSourceLookUpTest, PreservesParentPipelineLetVariables) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto varId = expCtx->variablesParseState.defineVariable("foo");
expCtx->variables.setValue(varId, Value(123));
@@ -109,7 +109,7 @@ TEST_F(DocumentSourceLookUpTest, PreservesParentPipelineLetVariables) {
TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnAsField) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "a");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create();
source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)};
@@ -132,7 +132,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnAsField) {
TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnSuffixOfAsField) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "a");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
intrusive_ptr<DocumentSourceMock> source = DocumentSourceMock::create();
source->sorts = {BSON("a" << 1 << "d.e" << 1 << "c" << 1)};
@@ -155,7 +155,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldTruncateOutputSortOnSuffixOfAsField) {
TEST_F(DocumentSourceLookUpTest, AcceptsPipelineSyntax) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
BSON("$lookup" << BSON("from"
@@ -173,7 +173,7 @@ TEST_F(DocumentSourceLookUpTest, AcceptsPipelineSyntax) {
TEST_F(DocumentSourceLookUpTest, AcceptsPipelineWithLetSyntax) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
BSON("$lookup" << BSON("from"
@@ -225,7 +225,7 @@ TEST_F(DocumentSourceLookUpTest, LiteParsedDocumentSourceLookupContainsExpectedN
TEST_F(DocumentSourceLookUpTest, RejectLookupWhenDepthLimitIsExceeded) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
expCtx->subPipelineDepth = DocumentSourceLookUp::kMaxSubPipelineDepth;
@@ -245,7 +245,7 @@ TEST_F(DocumentSourceLookUpTest, RejectLookupWhenDepthLimitIsExceeded) {
TEST_F(ReplDocumentSourceLookUpTest, RejectsPipelineWithChangeStreamStage) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Verify that attempting to create a $lookup pipeline containing a $changeStream stage fails.
ASSERT_THROWS_CODE(
@@ -260,7 +260,7 @@ TEST_F(ReplDocumentSourceLookUpTest, RejectsPipelineWithChangeStreamStage) {
TEST_F(ReplDocumentSourceLookUpTest, RejectsSubPipelineWithChangeStreamStage) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Verify that attempting to create a sub-$lookup pipeline containing a $changeStream stage
// fails at parse time, even if the outer pipeline does not have a $changeStream stage.
@@ -277,7 +277,7 @@ TEST_F(ReplDocumentSourceLookUpTest, RejectsSubPipelineWithChangeStreamStage) {
TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenPipelineIsSpecified) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
try {
auto lookupStage = DocumentSourceLookUp::createFromBson(
@@ -306,7 +306,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenPipelineIsSpec
TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenLetIsSpecified) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson(BSON("$lookup" << BSON("from"
<< "coll"
@@ -328,7 +328,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsLocalFieldForeignFieldWhenLetIsSpecified
TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
ASSERT_THROWS_CODE(DocumentSourceLookUp::createFromBson(
BSON("$lookup" << BSON("from"
@@ -379,7 +379,7 @@ TEST_F(DocumentSourceLookUpTest, RejectsInvalidLetVariableName) {
TEST_F(DocumentSourceLookUpTest, ShouldBeAbleToReParseSerializedStage) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto lookupStage = DocumentSourceLookUp::createFromBson(
BSON("$lookup" << BSON("from"
@@ -540,7 +540,7 @@ private:
TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "foreign");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Set up the $lookup stage.
auto lookupSpec = Document{{"$lookup",
@@ -591,7 +591,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) {
TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "foreign");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Set up the $lookup stage.
auto lookupSpec = Document{{"$lookup",
@@ -644,7 +644,7 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePausesWhileUnwinding) {
TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "foreign");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Set up the $lookup stage.
auto lookupSpec = Document{{"$lookup",
@@ -666,7 +666,7 @@ TEST_F(DocumentSourceLookUpTest, LookupReportsAsFieldIsModified) {
TEST_F(DocumentSourceLookUpTest, LookupReportsFieldsModifiedByAbsorbedUnwind) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "foreign");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Set up the $lookup stage.
auto lookupSpec = Document{{"$lookup",
@@ -699,7 +699,7 @@ BSONObj sequentialCacheStageObj(const StringData status = "kBuilding"_sd,
TEST_F(DocumentSourceLookUpTest, ShouldCacheNonCorrelatedSubPipelinePrefix) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
fromjson("{$lookup: {let: {var1: '$_id'}, pipeline: [{$match: {x:1}}, {$sort: {x: 1}}, "
@@ -728,7 +728,7 @@ TEST_F(DocumentSourceLookUpTest,
ShouldDiscoverVariablesReferencedInFacetPipelineAfterAnExhaustiveAllStage) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// In the $facet stage here, the correlated $match stage comes after a $group stage which
// returns EXHAUSTIVE_ALL for its dependencies. Verify that we continue enumerating the $facet
@@ -763,7 +763,7 @@ TEST_F(DocumentSourceLookUpTest,
TEST_F(DocumentSourceLookUpTest, ExprEmbeddedInMatchExpressionShouldBeOptimized) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// This pipeline includes a $match stage that itself includes a $expr expression.
auto docSource = DocumentSourceLookUp::createFromBson(
@@ -802,7 +802,7 @@ TEST_F(DocumentSourceLookUpTest,
ShouldIgnoreLocalVariablesShadowingLetVariablesWhenFindingNonCorrelatedPrefix) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// The $project stage defines a local variable with the same name as the $lookup 'let' variable.
// Verify that the $project is identified as non-correlated and the cache is placed after it.
@@ -836,7 +836,7 @@ TEST_F(DocumentSourceLookUpTest,
TEST_F(DocumentSourceLookUpTest, ShouldInsertCacheBeforeCorrelatedNestedLookup) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Create a $lookup stage whose pipeline contains nested $lookups. The third-level $lookup
// refers to a 'let' variable defined in the top-level $lookup. Verify that the second-level
@@ -873,7 +873,7 @@ TEST_F(DocumentSourceLookUpTest,
ShouldIgnoreNestedLookupLetVariablesShadowingOuterLookupLetVariablesWhenFindingPrefix) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// The nested $lookup stage defines a 'let' variable with the same name as the top-level 'let'.
// Verify the nested $lookup is identified as non-correlated and the cache is placed after it.
@@ -907,7 +907,7 @@ TEST_F(DocumentSourceLookUpTest,
TEST_F(DocumentSourceLookUpTest, ShouldCacheEntirePipelineIfNonCorrelated) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
fromjson("{$lookup: {let: {}, pipeline: [{$match: {x:1}}, {$sort: {x: 1}}, {$lookup: "
@@ -940,7 +940,7 @@ TEST_F(DocumentSourceLookUpTest,
ShouldReplaceNonCorrelatedPrefixWithCacheAfterFirstSubPipelineIteration) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
fromjson(
@@ -1014,7 +1014,7 @@ TEST_F(DocumentSourceLookUpTest,
ShouldAbandonCacheIfMaxSizeIsExceededAfterFirstSubPipelineIteration) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
// Ensure the cache is abandoned after the first iteration by setting its max size to 0.
size_t maxCacheSizeBytes = 0;
@@ -1079,7 +1079,7 @@ TEST_F(DocumentSourceLookUpTest,
TEST_F(DocumentSourceLookUpTest, ShouldNotCacheIfCorrelatedStageIsAbsorbedIntoPlanExecutor) {
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
- expCtx->setResolvedNamespace(fromNs, {fromNs, std::vector<BSONObj>{}});
+ expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
auto docSource = DocumentSourceLookUp::createFromBson(
fromjson("{$lookup: {let: {var1: '$_id'}, pipeline: [{$match: {$expr: { $gte: ['$x', "