diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2019-05-10 17:09:02 -0400 |
---|---|---|
committer | Ben Caimano <ben.caimano@10gen.com> | 2019-08-15 11:15:30 -0400 |
commit | e01bb51154d87a0b9931a63a444b4fdb20b8f530 (patch) | |
tree | a753e144bc5ebfc41c505e001a3499a45761b9c3 | |
parent | 21c694fda7114932d73795f89ff52b25f8ec09c6 (diff) | |
download | mongo-e01bb51154d87a0b9931a63a444b4fdb20b8f530.tar.gz |
SERVER-41102 Join threads in transport_layer_asio_test
(cherry picked from commit f39e80db634a58d63f038674e821bae9cacd1dd7)
-rw-r--r-- | src/mongo/transport/transport_layer_asio_test.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/mongo/transport/transport_layer_asio_test.cpp b/src/mongo/transport/transport_layer_asio_test.cpp index f6aeb2ff486..948c1e02962 100644 --- a/src/mongo/transport/transport_layer_asio_test.cpp +++ b/src/mongo/transport/transport_layer_asio_test.cpp @@ -165,11 +165,20 @@ TEST(TransportLayerASIO, PortZeroConnect) { class TimeoutSEP : public ServiceEntryPoint { public: + ~TimeoutSEP() override { + // This should shutdown immediately, so give the maximum timeout + shutdown(Milliseconds::max()); + } + void endAllSessions(transport::Session::TagMask tags) override { MONGO_UNREACHABLE; } bool shutdown(Milliseconds timeout) override { + log() << "Joining all worker threads"; + for (auto& thread : _workerThreads) { + thread.join(); + } return true; } @@ -207,10 +216,18 @@ protected: _cond.notify_one(); } + template <typename FunT> + void startWorkerThread(FunT&& fun) { + _workerThreads.emplace_back(std::forward<FunT>(fun)); + } + private: stdx::mutex _mutex; + stdx::condition_variable _cond; bool _finished = false; + + std::vector<stdx::thread> _workerThreads; }; class TimeoutSyncSEP : public TimeoutSEP { @@ -220,7 +237,7 @@ public: void startSession(transport::SessionHandle session) override { log() << "Accepted connection from " << session->remote(); - stdx::thread([ this, session = std::move(session) ]() mutable { + startWorkerThread([ this, session = std::move(session) ]() mutable { log() << "waiting for message"; session->setTimeout(Milliseconds{500}); auto status = session->sourceMessage().getStatus(); @@ -234,7 +251,7 @@ public: session.reset(); notifyComplete(); - }).detach(); + }); } private: @@ -315,7 +332,7 @@ class TimeoutSwitchModesSEP : public TimeoutSEP { public: void startSession(transport::SessionHandle session) override { log() << "Accepted connection from " << session->remote(); - stdx::thread worker([ this, session = std::move(session) ]() mutable { + startWorkerThread([ this, session = std::move(session) ]() mutable { log() << "waiting for message"; auto sourceMessage = [&] { return session->sourceMessage().getStatus(); }; @@ -342,7 +359,6 @@ public: notifyComplete(); log() << "ending test"; }); - worker.detach(); } }; |