diff options
author | Alya Berciu <alya.berciu@mongodb.com> | 2019-06-03 17:57:51 -0400 |
---|---|---|
committer | Alya Berciu <alya.berciu@mongodb.com> | 2019-06-13 16:50:54 -0400 |
commit | f90df932ab3f8c5f279b6f14343fe0efa80c1b9a (patch) | |
tree | 0e4de78f318c9ee03b7352b113e25fbf31c72cce | |
parent | b0a979f1ac92bc5ef9f916107d3c5bb1af236fb2 (diff) | |
download | mongo-f90df932ab3f8c5f279b6f14343fe0efa80c1b9a.tar.gz |
SERVER-35797 Add timeout value to NetworkInterfaceExceededTimeLimit messages
-rw-r--r-- | src/mongo/executor/connection_pool.cpp | 10 | ||||
-rw-r--r-- | src/mongo/executor/connection_pool_test.cpp | 21 |
2 files changed, 21 insertions, 10 deletions
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp index 15c0a791a66..a50438991c2 100644 --- a/src/mongo/executor/connection_pool.cpp +++ b/src/mongo/executor/connection_pool.cpp @@ -29,6 +29,9 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kConnectionPool +#include <fmt/format.h> +#include <fmt/ostream.h> + #include "mongo/platform/basic.h" #include "mongo/executor/connection_pool.h" @@ -997,7 +1000,7 @@ void ConnectionPool::SpecificPool::updateEventTimer() { _eventTimer->cancelTimeout(); // Set our event timer to timeout requests, refresh the state, and potentially expire this pool - auto deferredStateUpdateFunc = guardCallback([this]() { + auto deferredStateUpdateFunc = guardCallback([this, timeout]() { auto now = _parent->_factory->now(); _health.isFailed = false; @@ -1006,8 +1009,9 @@ void ConnectionPool::SpecificPool::updateEventTimer() { std::pop_heap(begin(_requests), end(_requests), RequestComparator{}); auto& request = _requests.back(); - request.second.setError(Status(ErrorCodes::NetworkInterfaceExceededTimeLimit, - "Couldn't get a connection within the time limit")); + request.second.setError(Status( + ErrorCodes::NetworkInterfaceExceededTimeLimit, + fmt::format("Couldn't get a connection within the time limit of {}", timeout))); _requests.pop_back(); // Since we've failed a request, we've interacted with external users diff --git a/src/mongo/executor/connection_pool_test.cpp b/src/mongo/executor/connection_pool_test.cpp index e839371dbcd..e5775bcdfd5 100644 --- a/src/mongo/executor/connection_pool_test.cpp +++ b/src/mongo/executor/connection_pool_test.cpp @@ -37,6 +37,9 @@ #include <stack> #include <tuple> +#include <fmt/format.h> +#include <fmt/ostream.h> + #include "mongo/executor/connection_pool.h" #include "mongo/stdx/future.h" #include "mongo/unittest/unittest.h" @@ -397,20 +400,24 @@ TEST_F(ConnectionPoolTest, DifferentConnWithoutReturn) { TEST_F(ConnectionPoolTest, TimeoutOnSetup) { auto pool = makePool(); - bool notOk = false; - auto now = Date_t::now(); + Milliseconds hostTimeout = Milliseconds(5000); + PoolImpl::setNow(now); + boost::optional<StatusWith<ConnectionPool::ConnectionHandle>> conn; pool->get_forTest( - HostAndPort(), - Milliseconds(5000), - [&](StatusWith<ConnectionPool::ConnectionHandle> swConn) { notOk = !swConn.isOK(); }); + HostAndPort(), hostTimeout, [&](StatusWith<ConnectionPool::ConnectionHandle> swConn) { + conn = std::move(swConn); + }); - PoolImpl::setNow(now + Milliseconds(5000)); + PoolImpl::setNow(now + hostTimeout); - ASSERT(notOk); + ASSERT(!conn->isOK()); + ASSERT_EQ(conn->getStatus(), ErrorCodes::NetworkInterfaceExceededTimeLimit); + ASSERT_STRING_CONTAINS(conn->getStatus().reason(), + fmt::format("{}", ConnectionPool::kHostRetryTimeout)); } /** |