diff options
-rw-r--r-- | src/bin/netconf/tests/control_socket_unittests.cc | 10 | ||||
-rw-r--r-- | src/lib/config/cmd_http_listener.cc | 6 | ||||
-rw-r--r-- | src/lib/http/client.cc | 8 | ||||
-rw-r--r-- | src/lib/http/tests/client_mt_unittests.cc | 34 | ||||
-rw-r--r-- | src/lib/tcp/mt_tcp_listener_mgr.cc | 6 | ||||
-rw-r--r-- | src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc | 14 |
6 files changed, 40 insertions, 38 deletions
diff --git a/src/bin/netconf/tests/control_socket_unittests.cc b/src/bin/netconf/tests/control_socket_unittests.cc index f0abe133d4..924495ac63 100644 --- a/src/bin/netconf/tests/control_socket_unittests.cc +++ b/src/bin/netconf/tests/control_socket_unittests.cc @@ -551,6 +551,11 @@ public: /// /// Run IO in a thread. void start() { + // If the thread is ready to go, start the listener. + if (listener_) { + ASSERT_NO_THROW_LOG(listener_->start()); + } + thread_.reset(new thread([this]() { // The thread is ready to go. Signal it to the main // thread so it can start the actual test. @@ -571,11 +576,6 @@ public: // Main thread waits here for the thread to start. waitReady(); - - // If the thread is ready to go, start the listener. - if (listener_) { - ASSERT_NO_THROW_LOG(listener_->start()); - } } /// @brief Stop listener. diff --git a/src/lib/config/cmd_http_listener.cc b/src/lib/config/cmd_http_listener.cc index c5e8d30b46..83408a6a24 100644 --- a/src/lib/config/cmd_http_listener.cc +++ b/src/lib/config/cmd_http_listener.cc @@ -67,13 +67,13 @@ CmdHttpListener::start() { HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND), HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT))); - // Create the thread pool with immediate start. - thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_)); - // Instruct the HTTP listener to actually open socket, install // callback and start listening. http_listener_->start(); + // Create the thread pool with immediate start. + thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_)); + // OK, seems like we're good to go. LOG_DEBUG(command_logger, DBG_COMMAND, COMMAND_HTTP_LISTENER_STARTED) .arg(thread_pool_size_) diff --git a/src/lib/http/client.cc b/src/lib/http/client.cc index 18d535effd..47b15d4b93 100644 --- a/src/lib/http/client.cc +++ b/src/lib/http/client.cc @@ -1790,14 +1790,14 @@ public: // Create our own private IOService. thread_io_service_.reset(new IOService()); - // Create the thread pool. - thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_, - defer_thread_start)); - // Create the connection pool. Note that we use the thread_pool_size // as the maximum connections per URL value. conn_pool_.reset(new ConnectionPool(*thread_io_service_, thread_pool_size_)); + // Create the thread pool. + thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_, + defer_thread_start)); + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC, HTTP_CLIENT_MT_STARTED) .arg(thread_pool_size_); } else { diff --git a/src/lib/http/tests/client_mt_unittests.cc b/src/lib/http/tests/client_mt_unittests.cc index 0d8944abcf..1111a87bc6 100644 --- a/src/lib/http/tests/client_mt_unittests.cc +++ b/src/lib/http/tests/client_mt_unittests.cc @@ -481,7 +481,7 @@ public: } // Create an MT client with num_threads - ASSERT_NO_THROW_LOG(client_.reset(new HttpClient(io_service_, num_threads))); + ASSERT_NO_THROW_LOG(client_.reset(new HttpClient(io_service_, num_threads, true))); ASSERT_TRUE(client_); if (num_threads_ == 0) { @@ -492,10 +492,6 @@ public: ASSERT_TRUE(client_->getThreadIOService()); } - // Verify the pool size and number of threads are as expected. - ASSERT_EQ(client_->getThreadPoolSize(), num_threads); - ASSERT_EQ(client_->getThreadCount(), num_threads); - // Start the requisite number of requests: // batch * listeners * threads. int sequence = 0; @@ -507,6 +503,12 @@ public: } } + client_->start(); + + // Verify the pool size and number of threads are as expected. + ASSERT_EQ(client_->getThreadPoolSize(), num_threads); + ASSERT_EQ(client_->getThreadCount(), num_threads); + // Loop until the clients are done, an error occurs, or the time runs out. runIOService(expected_requests_); @@ -645,18 +647,9 @@ public: } // Create an instant start, MT client with num_threads - ASSERT_NO_THROW_LOG(client_.reset(new HttpClient(io_service_, num_threads))); + ASSERT_NO_THROW_LOG(client_.reset(new HttpClient(io_service_, num_threads, true))); ASSERT_TRUE(client_); - // Client should be running. Check convenience functions. - ASSERT_TRUE(client_->isRunning()); - ASSERT_FALSE(client_->isPaused()); - ASSERT_FALSE(client_->isStopped()); - - // Verify the pool size and number of threads are as expected. - ASSERT_EQ(client_->getThreadPoolSize(), num_threads); - ASSERT_EQ(client_->getThreadCount(), num_threads); - // Start the requisite number of requests: // batch * listeners * threads. int sequence = 0; @@ -668,6 +661,17 @@ public: } } + client_->start(); + + // Client should be running. Check convenience functions. + ASSERT_TRUE(client_->isRunning()); + ASSERT_FALSE(client_->isPaused()); + ASSERT_FALSE(client_->isStopped()); + + // Verify the pool size and number of threads are as expected. + ASSERT_EQ(client_->getThreadPoolSize(), num_threads); + ASSERT_EQ(client_->getThreadCount(), num_threads); + size_t rr_count = 0; while (rr_count < total_requests) { size_t request_limit = (pause_cnt_ < num_pauses ? diff --git a/src/lib/tcp/mt_tcp_listener_mgr.cc b/src/lib/tcp/mt_tcp_listener_mgr.cc index 66a27e4e98..afc270990f 100644 --- a/src/lib/tcp/mt_tcp_listener_mgr.cc +++ b/src/lib/tcp/mt_tcp_listener_mgr.cc @@ -64,13 +64,13 @@ MtTcpListenerMgr::start() { idle_timeout_, connection_filter_); - // Create the thread pool with immediate start. - thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_)); - // Instruct the HTTP listener to actually open socket, install // callback and start listening. tcp_listener_->start(); + // Create the thread pool with immediate start. + thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_)); + // OK, seems like we're good to go. LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_BASIC, MT_TCP_LISTENER_MGR_STARTED) .arg(thread_pool_size_) diff --git a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc index cbffd75d07..ab561c6010 100644 --- a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc +++ b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc @@ -80,7 +80,7 @@ public: /// @brief Replaces the test's listener with a new listener /// - /// @param num_threads Number of threads the listener should use. + /// @param num_threads Number of threads the listener should use. /// @param response_handler Response handler connections should use void createMtTcpListenerMgr(size_t num_threads, TcpTestConnection::ResponseHandler response_handler = 0) { @@ -99,13 +99,13 @@ public: AuditTrailPtr getAuditTrail() { TcpListenerPtr l = mt_listener_mgr_->getTcpListener(); if (!l) { - isc_throw(Unexpected, "Test is broken? Listener is null?"); + isc_throw(Unexpected, "Test is broken? Listener is null?"); } TcpTestListenerPtr listener = boost::dynamic_pointer_cast<TcpTestListener>( mt_listener_mgr_->getTcpListener()); if (!listener) { - isc_throw(Unexpected, "Test is broken? Listener is not a TcpTestListener"); + isc_throw(Unexpected, "Test is broken? Listener is not a TcpTestListener"); } return (listener->audit_trail_); @@ -280,7 +280,6 @@ public: } } - // Create the map of response arguments. ElementPtr arguments = Element::createMap(); @@ -426,7 +425,7 @@ public: chunk_size_ = num_clients_; } - // Create an MtTcpListenerMgr with prescribed number of threads. + // Create an MtTcpListenerMgr with prescribed number of threads. createMtTcpListenerMgr(num_threads, std::bind(&MtTcpListenerMgrTest::synchronizedCommandHandler, this, ph::_1)); @@ -561,7 +560,7 @@ public: num_threads_ = num_threads; num_clients_ = num_clients; - // Create an MtTcpListenerMgr with prescribed number of threads and the + // Create an MtTcpListenerMgr with prescribed number of threads and the // simple handler. createMtTcpListenerMgr(num_threads, std::bind(&MtTcpListenerMgrTest::simpleCommandHandler, @@ -962,7 +961,7 @@ TEST_F(MtTcpListenerMgrTest, tls) { /// Verifies that idle timeout can be passed down to the internal listener. TEST_F(MtTcpListenerMgrTest, idleTimeout) { - // Create an MtTcpListenerMgr. + // Create an MtTcpListenerMgr. createMtTcpListenerMgr(1, std::bind(&MtTcpListenerMgrTest::synchronizedCommandHandler, this, ph::_1)); // Verify the default timeout value. @@ -982,5 +981,4 @@ TEST_F(MtTcpListenerMgrTest, idleTimeout) { EXPECT_EQ(200, tcp_listener->getIdleTimeout()); } - } // end of anonymous namespace |