summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_group_test.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2018-06-22 12:00:21 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2018-09-13 12:11:32 -0400
commit58feaec9c55629ba253b1ff013736eb8b8e9c79d (patch)
tree2465d0dee70d9423e59cf263831cd2fe379e6eb8 /src/mongo/db/pipeline/document_source_group_test.cpp
parent1465239c3b92ba935cc5ebba57dbdf9256c18c57 (diff)
downloadmongo-58feaec9c55629ba253b1ff013736eb8b8e9c79d.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). (cherry picked from commit d520be0814492c262515cf0a5d62a127ace70dce) SERVER-35985 Destroy clients started in other threads. (cherry picked from commit 9a68eb0cc65a93233b4ff5746330f9eb77de9b90) SERVER-36258 Construct ServiceContext after mongo initializers complete. (cherry picked from commit bfe170e49b1dc10b2badde45bc13c057a2f8ab61) SERVER-36400 Explicitly destroy the client on exiting run() of each BackgroundJob (cherry picked from commit b079e4713d897b5541c2804386025817ec720800) SERVER-36351 Fix so ServiceContextMongoDTest removes the temp directory in its destructor. (cherry picked from commit 4c16f0f336f4db77034e8aa594bbd4a5bac3f40c) SERVER-36347 Fix parse_zone_info.py after ServiceContext refactor. (cherry picked from commit c9d4204b6243e5eee6fe0b5e2c34d02af9ac5edb)
Diffstat (limited to 'src/mongo/db/pipeline/document_source_group_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_group_test.cpp43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/mongo/db/pipeline/document_source_group_test.cpp b/src/mongo/db/pipeline/document_source_group_test.cpp
index de99452f3d7..44210e4a579 100644
--- a/src/mongo/db/pipeline/document_source_group_test.cpp
+++ b/src/mongo/db/pipeline/document_source_group_test.cpp
@@ -196,11 +196,10 @@ BSONObj toBson(const intrusive_ptr<DocumentSource>& source) {
return arr[0].getDocument().toBson();
}
-class Base {
+class Base : public ServiceContextTest {
public:
Base()
- : _queryServiceContext(stdx::make_unique<QueryTestServiceContext>()),
- _opCtx(_queryServiceContext->makeOperationContext()),
+ : _opCtx(makeOperationContext()),
_ctx(new ExpressionContextForTest(_opCtx.get(),
AggregationRequest(NamespaceString(ns), {}))),
_tempDir("DocumentSourceGroupTest") {}
@@ -257,7 +256,7 @@ private:
class ParseErrorBase : public Base {
public:
virtual ~ParseErrorBase() {}
- void run() {
+ void _doTest() final {
ASSERT_THROWS(createGroup(spec()), AssertionException);
}
@@ -268,7 +267,7 @@ protected:
class ExpressionBase : public Base {
public:
virtual ~ExpressionBase() {}
- void run() {
+ void _doTest() final {
createGroup(spec());
auto source = DocumentSourceMock::create(Document(doc()));
group()->setSource(source.get());
@@ -298,7 +297,7 @@ class IdConstantBase : public ExpressionBase {
/** $group spec is not an object. */
class NonObject : public Base {
public:
- void run() {
+ void _doTest() final {
BSONObj spec = BSON("$group"
<< "foo");
BSONElement specElement = spec.firstElement();
@@ -500,7 +499,7 @@ typedef map<Value, Document, ValueCmp> IdMap;
class CheckResultsBase : public Base {
public:
virtual ~CheckResultsBase() {}
- void run() {
+ void _doTest() {
runSharded(false);
runSharded(true);
}
@@ -726,7 +725,7 @@ class UndefinedAccumulatorValue : public CheckResultsBase {
/** Simulate merging sharded results in the router. */
class RouterMerger : public CheckResultsBase {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{_id:0,list:[1,2]}",
"{_id:1,list:[3,4]}",
"{_id:0,list:[10,20]}",
@@ -755,7 +754,7 @@ private:
/** Dependant field paths. */
class Dependencies : public Base {
public:
- void run() {
+ void _doTest() final {
createGroup(fromjson("{_id:'$x',a:{$sum:'$y.z'},b:{$avg:{$add:['$u','$v']}}}"));
DepsTracker dependencies;
ASSERT_EQUALS(DocumentSource::EXHAUSTIVE_ALL, group()->getDependencies(&dependencies));
@@ -773,7 +772,7 @@ public:
class StreamingOptimization : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 0}", "{a: 0}", "{a: 1}", "{a: 1}"});
source->sorts = {BSON("a" << 1)};
@@ -808,7 +807,7 @@ public:
class StreamingWithMultipleIdFields : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create(
{"{a: 1, b: 2}", "{a: 1, b: 2}", "{a: 1, b: 1}", "{a: 2, b: 1}", "{a: 2, b: 1}"});
source->sorts = {BSON("a" << 1 << "b" << -1)};
@@ -848,7 +847,7 @@ public:
class StreamingWithMultipleLevels : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create(
{"{a: {b: {c: 3}}, d: 1}", "{a: {b: {c: 1}}, d: 2}", "{a: {b: {c: 1}}, d: 0}"});
source->sorts = {BSON("a.b.c" << -1 << "a.b.d" << 1 << "d" << 1)};
@@ -884,7 +883,7 @@ public:
class StreamingWithFieldRepeated : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create(
{"{a: 1, b: 1}", "{a: 1, b: 1}", "{a: 2, b: 1}", "{a: 2, b: 3}"});
source->sorts = {BSON("a" << 1 << "b" << 1)};
@@ -919,7 +918,7 @@ public:
class StreamingWithConstantAndFieldPath : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create(
{"{a: 5, b: 1}", "{a: 5, b: 2}", "{a: 3, b: 1}", "{a: 1, b: 1}", "{a: 1, b: 1}"});
source->sorts = {BSON("a" << -1 << "b" << 1)};
@@ -953,7 +952,7 @@ public:
class StreamingWithRootSubfield : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1}", "{a: 2}", "{a: 3}"});
source->sorts = {BSON("a" << 1)};
@@ -973,7 +972,7 @@ public:
class StreamingWithConstant : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1}", "{a: 2}", "{a: 3}"});
source->sorts = {BSON("$a" << 1)};
@@ -990,7 +989,7 @@ public:
class StreamingWithEmptyId : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1}", "{a: 2}", "{a: 3}"});
source->sorts = {BSON("$a" << 1)};
@@ -1007,7 +1006,7 @@ public:
class NoOptimizationIfMissingDoubleSort : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1}", "{a: 2}", "{a: 3}"});
source->sorts = {BSON("a" << 1)};
@@ -1034,7 +1033,7 @@ public:
class NoOptimizationWithRawRoot : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1}", "{a: 2}", "{a: 3}"});
source->sorts = {BSON("a" << 1)};
@@ -1061,7 +1060,7 @@ public:
class NoOptimizationIfUsingExpressions : public Base {
public:
- void run() {
+ void _doTest() final {
auto source = DocumentSourceMock::create({"{a: 1, b: 1}", "{a: 2, b: 2}", "{a: 3, b: 1}"});
source->sorts = {BSON("a" << 1 << "b" << 1)};
@@ -1100,11 +1099,11 @@ class StringConstantIdAndAccumulatorExpressions : public CheckResultsBase {
/** An array constant passed to an accumulator. */
class ArrayConstantAccumulatorExpression : public CheckResultsBase {
public:
- void run() {
+ void _doTest() final {
// A parse exception is thrown when a raw array is provided to an accumulator.
ASSERT_THROWS(createGroup(fromjson("{_id:1,a:{$push:[4,5,6]}}")), AssertionException);
// Run standard base tests.
- CheckResultsBase::run();
+ CheckResultsBase::_doTest();
}
deque<DocumentSource::GetNextResult> inputData() {
return {Document()};