diff options
Diffstat (limited to 'src/mongo/executor')
-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)); } /** |