diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2018-06-22 12:00:21 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2018-06-22 12:32:29 -0400 |
commit | d520be0814492c262515cf0a5d62a127ace70dce (patch) | |
tree | e754e3cce243a7b51922b6d2a179a3d355ccefb7 /src/mongo/db/exec | |
parent | c0b942e3a80b9ccd8434ab0927d97cbd1862d19a (diff) | |
download | mongo-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/exec')
-rw-r--r-- | src/mongo/db/exec/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/db/exec/queued_data_stage_test.cpp | 25 | ||||
-rw-r--r-- | src/mongo/db/exec/sort_test.cpp | 29 |
3 files changed, 18 insertions, 40 deletions
diff --git a/src/mongo/db/exec/SConscript b/src/mongo/db/exec/SConscript index 70d48105e2c..ba19b626965 100644 --- a/src/mongo/db/exec/SConscript +++ b/src/mongo/db/exec/SConscript @@ -60,7 +60,7 @@ env.CppUnitTest( "$BUILD_DIR/mongo/db/auth/authmocks", "$BUILD_DIR/mongo/db/query_exec", "$BUILD_DIR/mongo/db/serveronly", - "$BUILD_DIR/mongo/db/service_context_d", + "$BUILD_DIR/mongo/db/service_context_d_test_fixture", "$BUILD_DIR/mongo/dbtests/mocklib", "$BUILD_DIR/mongo/util/clock_source_mock", ], @@ -75,7 +75,7 @@ env.CppUnitTest( "$BUILD_DIR/mongo/db/auth/authmocks", "$BUILD_DIR/mongo/db/query_exec", "$BUILD_DIR/mongo/db/serveronly", - "$BUILD_DIR/mongo/db/service_context_d", + "$BUILD_DIR/mongo/db/service_context_d_test_fixture", "$BUILD_DIR/mongo/dbtests/mocklib", "$BUILD_DIR/mongo/db/query/collation/collator_factory_mock", "$BUILD_DIR/mongo/db/query/collation/collator_interface_mock", diff --git a/src/mongo/db/exec/queued_data_stage_test.cpp b/src/mongo/db/exec/queued_data_stage_test.cpp index 960d832777a..de09994b2a0 100644 --- a/src/mongo/db/exec/queued_data_stage_test.cpp +++ b/src/mongo/db/exec/queued_data_stage_test.cpp @@ -35,9 +35,8 @@ #include <boost/optional.hpp> #include "mongo/db/exec/working_set.h" -#include "mongo/db/operation_context_noop.h" -#include "mongo/db/service_context.h" -#include "mongo/db/service_context_noop.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/service_context_d_test_fixture.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" @@ -49,30 +48,20 @@ namespace { using std::unique_ptr; using stdx::make_unique; -class QueuedDataStageTest : public unittest::Test { +class QueuedDataStageTest : public ServiceContextMongoDTest { public: QueuedDataStageTest() { - _service = stdx::make_unique<ServiceContextNoop>(); - _service->setFastClockSource(stdx::make_unique<ClockSourceMock>()); - _client = _service->makeClient("test"); - _opCtxNoop = _client->makeOperationContext(); - _opCtx = _opCtxNoop.get(); + getServiceContext()->setFastClockSource(stdx::make_unique<ClockSourceMock>()); + _opCtx = makeOperationContext(); } protected: OperationContext* getOpCtx() { - return _opCtx; + return _opCtx.get(); } private: - OperationContext* _opCtx; - - // Members of a class are destroyed in reverse order of declaration. - // The UniqueClient must be destroyed before the ServiceContextNoop is destroyed. - // The OperationContextNoop must be destroyed before the UniqueClient is destroyed. - std::unique_ptr<ServiceContextNoop> _service; - ServiceContext::UniqueClient _client; - ServiceContext::UniqueOperationContext _opCtxNoop; + ServiceContext::UniqueOperationContext _opCtx; }; // diff --git a/src/mongo/db/exec/sort_test.cpp b/src/mongo/db/exec/sort_test.cpp index 08f3f15580e..b45626b0999 100644 --- a/src/mongo/db/exec/sort_test.cpp +++ b/src/mongo/db/exec/sort_test.cpp @@ -36,11 +36,10 @@ #include "mongo/db/exec/queued_data_stage.h" #include "mongo/db/json.h" -#include "mongo/db/operation_context_noop.h" +#include "mongo/db/operation_context.h" #include "mongo/db/query/collation/collator_factory_mock.h" #include "mongo/db/query/collation/collator_interface_mock.h" -#include "mongo/db/service_context.h" -#include "mongo/db/service_context_noop.h" +#include "mongo/db/service_context_d_test_fixture.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" @@ -49,19 +48,17 @@ using namespace mongo; namespace { -class SortStageTest : public unittest::Test { +class SortStageTest : public ServiceContextMongoDTest { public: SortStageTest() { - _service = stdx::make_unique<ServiceContextNoop>(); - _service->setFastClockSource(stdx::make_unique<ClockSourceMock>()); - _client = _service->makeClient("test"); - _opCtxNoop = _client->makeOperationContext(); - _opCtx = _opCtxNoop.get(); - CollatorFactoryInterface::set(_service.get(), stdx::make_unique<CollatorFactoryMock>()); + getServiceContext()->setFastClockSource(stdx::make_unique<ClockSourceMock>()); + _opCtx = makeOperationContext(); + CollatorFactoryInterface::set(getServiceContext(), + stdx::make_unique<CollatorFactoryMock>()); } OperationContext* getOpCtx() { - return _opCtx; + return _opCtx.get(); } /** @@ -155,15 +152,7 @@ public: } private: - OperationContext* _opCtx; - - std::unique_ptr<ServiceContextNoop> _service; - - // Members of a class are destroyed in reverse order of declaration. - // The UniqueClient must be destroyed before the ServiceContextNoop is destroyed. - // The OperationContextNoop must be destroyed before the UniqueClient is destroyed. - ServiceContext::UniqueClient _client; - ServiceContext::UniqueOperationContext _opCtxNoop; + ServiceContext::UniqueOperationContext _opCtx; }; TEST_F(SortStageTest, SortEmptyWorkingSet) { |