diff options
author | Celina Tala <celinahtala@gmail.com> | 2022-10-06 14:00:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-01 18:55:38 +0000 |
commit | a170f2d160c42a7e7af48de775c97a693880fc1c (patch) | |
tree | 3d4b94eabb0f18f479dd361492431f3bb765647e /src | |
parent | a58c20209f4b63c4032a4df6caa8df19bd58c22c (diff) | |
download | mongo-a170f2d160c42a7e7af48de775c97a693880fc1c.tar.gz |
SERVER-69868 Return ShutdownStatus When Starting a Shutdown `TransportLayer`
(cherry picked from commit 29006706c176ca036120d1b2569c0f59dd8f53b6)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/transport/transport_layer_asio.cpp | 7 | ||||
-rw-r--r-- | src/mongo/transport/transport_layer_asio_test.cpp | 59 |
2 files changed, 46 insertions, 20 deletions
diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp index cfdd234d0a1..cda01dbfc38 100644 --- a/src/mongo/transport/transport_layer_asio.cpp +++ b/src/mongo/transport/transport_layer_asio.cpp @@ -1194,9 +1194,10 @@ void TransportLayerASIO::_runListener() noexcept { Status TransportLayerASIO::start() { stdx::unique_lock lk(_mutex); - - // Make sure we haven't shutdown already - invariant(!_isShutdown); + if (_isShutdown) { + LOGV2(6986801, "Cannot start an already shutdown TransportLayer"); + return ShutdownStatus; + } if (_listenerOptions.isIngress()) { _listener.thread = stdx::thread([this] { _runListener(); }); diff --git a/src/mongo/transport/transport_layer_asio_test.cpp b/src/mongo/transport/transport_layer_asio_test.cpp index 8ed6024a184..60138912f22 100644 --- a/src/mongo/transport/transport_layer_asio_test.cpp +++ b/src/mongo/transport/transport_layer_asio_test.cpp @@ -39,6 +39,7 @@ #include <fmt/format.h> #include "mongo/db/server_options.h" +#include "mongo/db/service_context_test_fixture.h" #include "mongo/logv2/log.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/basic.h" @@ -267,13 +268,29 @@ private: synchronized_value<std::vector<std::unique_ptr<SessionThread>>> _sessions; }; +std::unique_ptr<transport::TransportLayerASIO> makeTLA(ServiceEntryPoint* sep) { + auto options = [] { + ServerGlobalParams params; + params.noUnixSocket = true; + transport::TransportLayerASIO::Options opts(¶ms); + // TODO SERVER-30212 should clean this up and assign a port from the supplied port range + // provided by resmoke. + opts.port = 0; + return opts; + }(); + auto tla = std::make_unique<transport::TransportLayerASIO>(options, sep); + ASSERT_OK(tla->setup()); + ASSERT_OK(tla->start()); + return tla; +} + /** * Properly setting up and tearing down the MockSEP and TransportLayerASIO is * tricky. Most tests can delegate the details to this TestFixture. */ class TestFixture { public: - TestFixture() : _tla{_makeTLA()} {} + TestFixture() : _tla{makeTLA(&_sep)} {} ~TestFixture() { _sep.endAllSessions({}); @@ -289,22 +306,6 @@ public: } private: - std::unique_ptr<transport::TransportLayerASIO> _makeTLA() { - auto options = [] { - ServerGlobalParams params; - params.noUnixSocket = true; - transport::TransportLayerASIO::Options opts(¶ms); - // TODO SERVER-30212 should clean this up and assign a port from the supplied port range - // provided by resmoke. - opts.port = 0; - return opts; - }(); - auto tla = std::make_unique<transport::TransportLayerASIO>(options, &_sep); - ASSERT_OK(tla->setup()); - ASSERT_OK(tla->start()); - return tla; - } - std::unique_ptr<transport::TransportLayerASIO> _tla; MockSEP _sep; }; @@ -560,5 +561,29 @@ TEST(TransportLayerASIO, ConfirmSocketSetOptionOnResetConnections) { "msg"_attr = "{}"_format(thrown ? thrown->message() : "")); } +class TransportLayerASIOWithServiceContextTest : public ServiceContextTest { +public: + void setUp() override { + auto sep = std::make_unique<MockSEP>(); + auto tl = makeTLA(sep.get()); + getServiceContext()->setServiceEntryPoint(std::move(sep)); + getServiceContext()->setTransportLayer(std::move(tl)); + } + + void tearDown() override { + getServiceContext()->getTransportLayer()->shutdown(); + } + + transport::TransportLayerASIO& tla() { + auto tl = getServiceContext()->getTransportLayer(); + return *dynamic_cast<transport::TransportLayerASIO*>(tl); + } +}; + +TEST_F(TransportLayerASIOWithServiceContextTest, TransportStartAfterShutDown) { + tla().shutdown(); + ASSERT_EQ(tla().start(), transport::TransportLayer::ShutdownStatus); +} + } // namespace } // namespace mongo |