summaryrefslogtreecommitdiff
path: root/src/mongo/transport
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/transport
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/transport')
-rw-r--r--src/mongo/transport/SConscript2
-rw-r--r--src/mongo/transport/service_executor_adaptive_test.cpp5
-rw-r--r--src/mongo/transport/service_executor_test.cpp6
-rw-r--r--src/mongo/transport/service_state_machine_test.cpp4
-rw-r--r--src/mongo/transport/transport_layer_egress_init.cpp32
5 files changed, 22 insertions, 27 deletions
diff --git a/src/mongo/transport/SConscript b/src/mongo/transport/SConscript
index d12800b3273..0f61fbcf12c 100644
--- a/src/mongo/transport/SConscript
+++ b/src/mongo/transport/SConscript
@@ -74,7 +74,6 @@ env.Library(
],
LIBDEPS_PRIVATE=[
'transport_layer',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
]
)
@@ -86,7 +85,6 @@ tlEnv.CppUnitTest(
LIBDEPS=[
'transport_layer',
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/rpc/protocol',
'$BUILD_DIR/mongo/util/net/socket',
],
diff --git a/src/mongo/transport/service_executor_adaptive_test.cpp b/src/mongo/transport/service_executor_adaptive_test.cpp
index c851c738ac2..30227edf3b9 100644
--- a/src/mongo/transport/service_executor_adaptive_test.cpp
+++ b/src/mongo/transport/service_executor_adaptive_test.cpp
@@ -32,7 +32,7 @@
#include "boost/optional.hpp"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context.h"
#include "mongo/transport/service_executor_adaptive.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -107,8 +107,7 @@ struct RecursionOptions : public ServiceExecutorAdaptive::Options {
class ServiceExecutorAdaptiveFixture : public unittest::Test {
protected:
void setUp() override {
- auto scOwned = stdx::make_unique<ServiceContextNoop>();
- setGlobalServiceContext(std::move(scOwned));
+ setGlobalServiceContext(ServiceContext::make());
asioIoCtx = std::make_shared<asio::io_context>();
}
diff --git a/src/mongo/transport/service_executor_test.cpp b/src/mongo/transport/service_executor_test.cpp
index 8e749228631..86e7187a37f 100644
--- a/src/mongo/transport/service_executor_test.cpp
+++ b/src/mongo/transport/service_executor_test.cpp
@@ -32,7 +32,7 @@
#include "boost/optional.hpp"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context.h"
#include "mongo/transport/service_executor_adaptive.h"
#include "mongo/transport/service_executor_synchronous.h"
#include "mongo/transport/service_executor_task_names.h"
@@ -135,7 +135,7 @@ private:
class ServiceExecutorAdaptiveFixture : public unittest::Test {
protected:
void setUp() override {
- auto scOwned = stdx::make_unique<ServiceContextNoop>();
+ auto scOwned = ServiceContext::make();
setGlobalServiceContext(std::move(scOwned));
auto configOwned = stdx::make_unique<TestOptions>();
@@ -152,7 +152,7 @@ protected:
class ServiceExecutorSynchronousFixture : public unittest::Test {
protected:
void setUp() override {
- auto scOwned = stdx::make_unique<ServiceContextNoop>();
+ auto scOwned = ServiceContext::make();
setGlobalServiceContext(std::move(scOwned));
executor = stdx::make_unique<ServiceExecutorSynchronous>(getGlobalServiceContext());
diff --git a/src/mongo/transport/service_state_machine_test.cpp b/src/mongo/transport/service_state_machine_test.cpp
index 7ea13eaf12f..e29c33627a6 100644
--- a/src/mongo/transport/service_state_machine_test.cpp
+++ b/src/mongo/transport/service_state_machine_test.cpp
@@ -35,7 +35,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/client.h"
#include "mongo/db/dbmessage.h"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/stdx/memory.h"
#include "mongo/transport/mock_session.h"
@@ -272,7 +272,7 @@ class ServiceStateMachineFixture : public unittest::Test {
protected:
void setUp() override {
- auto scOwned = stdx::make_unique<ServiceContextNoop>();
+ auto scOwned = ServiceContext::make();
auto sc = scOwned.get();
setGlobalServiceContext(std::move(scOwned));
diff --git a/src/mongo/transport/transport_layer_egress_init.cpp b/src/mongo/transport/transport_layer_egress_init.cpp
index 628cf6c2dfc..ec8dd262515 100644
--- a/src/mongo/transport/transport_layer_egress_init.cpp
+++ b/src/mongo/transport/transport_layer_egress_init.cpp
@@ -34,25 +34,23 @@
#include "mongo/db/service_context.h"
#include "mongo/transport/transport_layer_asio.h"
+#include <iostream>
+
namespace mongo {
namespace {
-// Linking with this file will configure an egress-only TransportLayer on a ServiceContextNoop.
+// Linking with this file will configure an egress-only TransportLayer on all new ServiceContexts.
// Use this for unit/integration tests that require only egress networking.
-MONGO_INITIALIZER_WITH_PREREQUISITES(ConfigureEgressTransportLayer, ("ServiceContext"))
-(InitializerContext* context) {
- auto sc = getGlobalServiceContext();
- invariant(!sc->getTransportLayer());
-
- transport::TransportLayerASIO::Options opts;
- opts.mode = transport::TransportLayerASIO::Options::kEgress;
- sc->setTransportLayer(std::make_unique<transport::TransportLayerASIO>(opts, nullptr));
- auto status = sc->getTransportLayer()->setup();
- if (!status.isOK()) {
- return status;
- }
-
- return sc->getTransportLayer()->start();
-}
+
+ServiceContext::ConstructorActionRegisterer registerEgressTransportLayer{
+ "ConfigureEgressTransportLayer", [](ServiceContext* sc) {
+
+ invariant(!sc->getTransportLayer());
+ transport::TransportLayerASIO::Options opts;
+ opts.mode = transport::TransportLayerASIO::Options::kEgress;
+ sc->setTransportLayer(std::make_unique<transport::TransportLayerASIO>(opts, nullptr));
+ uassertStatusOK(sc->getTransportLayer()->setup());
+ uassertStatusOK(sc->getTransportLayer()->start());
+ }};
} // namespace
-} // namespace
+} // namespace mongo