summaryrefslogtreecommitdiff
path: root/src/mongo/executor/network_interface_integration_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/executor/network_interface_integration_test.cpp')
-rw-r--r--src/mongo/executor/network_interface_integration_test.cpp124
1 files changed, 30 insertions, 94 deletions
diff --git a/src/mongo/executor/network_interface_integration_test.cpp b/src/mongo/executor/network_interface_integration_test.cpp
index 1722084ac3b..fdf1ac6f8ba 100644
--- a/src/mongo/executor/network_interface_integration_test.cpp
+++ b/src/mongo/executor/network_interface_integration_test.cpp
@@ -50,7 +50,6 @@
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
-#include "mongo/util/fail_point.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -161,7 +160,7 @@ public:
}
void setUp() override {
- startNet(std::make_unique<WaitForHelloHook>(this));
+ startNet(std::make_unique<WaitForIsMasterHook>(this));
}
// NetworkInterfaceIntegrationFixture::tearDown() shuts down the NetworkInterface. We always
@@ -254,33 +253,33 @@ public:
return ++numCurrentOpRan;
}
- struct HelloData {
+ struct IsMasterData {
BSONObj request;
RemoteCommandResponse response;
};
- HelloData waitForHello() {
+ IsMasterData waitForIsMaster() {
stdx::unique_lock<Latch> lk(_mutex);
- _helloCondVar.wait(lk, [this] { return _helloResult != boost::none; });
+ _isMasterCond.wait(lk, [this] { return _isMasterResult != boost::none; });
- return std::move(*_helloResult);
+ return std::move(*_isMasterResult);
}
- bool hasHelloResult() {
+ bool hasIsMaster() {
stdx::lock_guard<Latch> lk(_mutex);
- return _helloResult != boost::none;
+ return _isMasterResult != boost::none;
}
private:
- class WaitForHelloHook : public NetworkConnectionHook {
+ class WaitForIsMasterHook : public NetworkConnectionHook {
public:
- explicit WaitForHelloHook(NetworkInterfaceTest* parent) : _parent(parent) {}
+ explicit WaitForIsMasterHook(NetworkInterfaceTest* parent) : _parent(parent) {}
Status validateHost(const HostAndPort& host,
const BSONObj& request,
- const RemoteCommandResponse& helloReply) override {
+ const RemoteCommandResponse& isMasterReply) override {
stdx::lock_guard<Latch> lk(_parent->_mutex);
- _parent->_helloResult = HelloData{request, helloReply};
- _parent->_helloCondVar.notify_all();
+ _parent->_isMasterResult = IsMasterData{request, isMasterReply};
+ _parent->_isMasterCond.notify_all();
return Status::OK();
}
@@ -297,8 +296,8 @@ private:
};
Mutex _mutex = MONGO_MAKE_LATCH("NetworkInterfaceTest::_mutex");
- stdx::condition_variable _helloCondVar;
- boost::optional<HelloData> _helloResult;
+ stdx::condition_variable _isMasterCond;
+ boost::optional<IsMasterData> _isMasterResult;
};
class NetworkInterfaceInternalClientTest : public NetworkInterfaceTest {
@@ -329,7 +328,7 @@ TEST_F(NetworkInterfaceTest, CancelLocally) {
auto deferred = runCommand(cbh, makeTestCommand(kMaxWait, makeEchoCmdObj()));
- waitForHello();
+ waitForIsMaster();
fpb->waitForTimesEntered(fpb.initialTimesEntered() + 1);
@@ -504,35 +503,13 @@ TEST_F(NetworkInterfaceTest, LateCancel) {
assertNumOps(0u, 0u, 0u, 1u);
}
-TEST_F(NetworkInterfaceTest, ConnectionErrorDropsSingleConnection) {
- FailPoint* failPoint =
- globalFailPointRegistry().find("transportLayerASIOasyncConnectReturnsConnectionError");
- auto timesEntered = failPoint->setMode(FailPoint::nTimes, 1);
-
- auto cbh = makeCallbackHandle();
- auto deferred = runCommand(cbh, makeTestCommand(kMaxWait, makeEchoCmdObj()));
- // Wait for one of the connection attempts to fail with a `ConnectionError`.
- failPoint->waitForTimesEntered(timesEntered + 1);
- auto result = deferred.get();
-
- ASSERT_OK(result.status);
- ConnectionPoolStats stats;
- net().appendConnectionStats(&stats);
-
- ASSERT_EQ(stats.totalCreated, 2);
- ASSERT_EQ(stats.totalInUse + stats.totalAvailable + stats.totalRefreshing, 1);
- // Connection dropped during finishRefresh, so the dropped connection still
- // counts toward the refreshed counter.
- ASSERT_EQ(stats.totalRefreshed, 2);
-}
-
TEST_F(NetworkInterfaceTest, AsyncOpTimeout) {
// Kick off operation
auto cb = makeCallbackHandle();
auto request = makeTestCommand(Milliseconds{1000}, makeSleepCmdObj());
auto deferred = runCommand(cb, request);
- waitForHello();
+ waitForIsMaster();
auto result = deferred.get();
@@ -556,19 +533,13 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineSooner) {
serviceContext->registerClientObserver(std::make_unique<LockerNoopClientObserver>());
auto client = serviceContext->makeClient("NetworkClient");
auto opCtx = client->makeOperationContext();
-
- auto stopWatch = serviceContext->getPreciseClockSource()->makeStopWatch();
- opCtx->setDeadlineByDate(stopWatch.start() + opCtxDeadline, ErrorCodes::ExceededTimeLimit);
+ opCtx->setDeadlineAfterNowBy(opCtxDeadline, ErrorCodes::ExceededTimeLimit);
auto request = makeTestCommand(requestTimeout, makeSleepCmdObj(), opCtx.get());
auto deferred = runCommand(cb, request);
- // The time returned in result.elapsed is measured from when the command started, which happens
- // in runCommand. The delay between setting the deadline on opCtx and starting the command can
- // be long enough that the assertion about opCtxDeadline fails.
- auto networkStartCommandDelay = stopWatch.elapsed();
- waitForHello();
+ waitForIsMaster();
auto result = deferred.get();
@@ -580,10 +551,9 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineSooner) {
ASSERT_EQ(ErrorCodes::ExceededTimeLimit, result.status);
ASSERT(result.elapsed);
-
// check that the request timeout uses the smaller of the operation context deadline and
// the timeout specified in the request constructor.
- ASSERT_GTE(result.elapsed.value() + networkStartCommandDelay, opCtxDeadline);
+ ASSERT_GTE(result.elapsed.value(), opCtxDeadline);
ASSERT_LT(result.elapsed.value(), requestTimeout);
assertNumOps(0u, 1u, 0u, 0u);
}
@@ -599,19 +569,12 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineLater) {
serviceContext->registerClientObserver(std::make_unique<LockerNoopClientObserver>());
auto client = serviceContext->makeClient("NetworkClient");
auto opCtx = client->makeOperationContext();
-
- auto stopWatch = serviceContext->getPreciseClockSource()->makeStopWatch();
- opCtx->setDeadlineByDate(stopWatch.start() + opCtxDeadline, ErrorCodes::ExceededTimeLimit);
-
+ opCtx->setDeadlineAfterNowBy(opCtxDeadline, ErrorCodes::ExceededTimeLimit);
auto request = makeTestCommand(requestTimeout, makeSleepCmdObj(), opCtx.get());
auto deferred = runCommand(cb, request);
- // The time returned in result.elapsed is measured from when the command started, which happens
- // in runCommand. The delay between setting the deadline on opCtx and starting the command can
- // be long enough that the assertion about opCtxDeadline fails.
- auto networkStartCommandDelay = stopWatch.elapsed();
- waitForHello();
+ waitForIsMaster();
auto result = deferred.get();
@@ -623,12 +586,10 @@ TEST_F(NetworkInterfaceTest, AsyncOpTimeoutWithOpCtxDeadlineLater) {
ASSERT_EQ(ErrorCodes::NetworkInterfaceExceededTimeLimit, result.status);
ASSERT(result.elapsed);
-
// check that the request timeout uses the smaller of the operation context deadline and
// the timeout specified in the request constructor.
ASSERT_GTE(duration_cast<Milliseconds>(result.elapsed.value()), requestTimeout);
- ASSERT_LT(duration_cast<Milliseconds>(result.elapsed.value() + networkStartCommandDelay),
- opCtxDeadline);
+ ASSERT_LT(duration_cast<Milliseconds>(result.elapsed.value()), opCtxDeadline);
assertNumOps(0u, 1u, 0u, 0u);
}
@@ -772,13 +733,13 @@ TEST_F(NetworkInterfaceTest, SetAlarm) {
}
TEST_F(NetworkInterfaceInternalClientTest,
- HelloRequestContainsOutgoingWireVersionInternalClientInfo) {
+ IsMasterRequestContainsOutgoingWireVersionInternalClientInfo) {
auto deferred = runCommand(makeCallbackHandle(), makeTestCommand(kNoTimeout, makeEchoCmdObj()));
- auto helloHandshake = waitForHello();
+ auto isMasterHandshake = waitForIsMaster();
- // Verify that the "hello" reply has the expected internalClient data.
+ // Verify that the isMaster reply has the expected internalClient data.
auto wireSpec = WireSpec::instance().get();
- auto internalClientElem = helloHandshake.request["internalClient"];
+ auto internalClientElem = isMasterHandshake.request["internalClient"];
ASSERT_EQ(internalClientElem.type(), BSONType::Object);
auto minWireVersionElem = internalClientElem.Obj()["minWireVersion"];
auto maxWireVersionElem = internalClientElem.Obj()["maxWireVersion"];
@@ -793,14 +754,14 @@ TEST_F(NetworkInterfaceInternalClientTest,
assertNumOps(0u, 0u, 0u, 1u);
}
-TEST_F(NetworkInterfaceTest, HelloRequestMissingInternalClientInfoWhenNotInternalClient) {
+TEST_F(NetworkInterfaceTest, IsMasterRequestMissingInternalClientInfoWhenNotInternalClient) {
resetIsInternalClient(false);
auto deferred = runCommand(makeCallbackHandle(), makeTestCommand(kNoTimeout, makeEchoCmdObj()));
- auto helloHandshake = waitForHello();
+ auto isMasterHandshake = waitForIsMaster();
- // Verify that the "hello" reply has the expected internalClient data.
- ASSERT_FALSE(helloHandshake.request["internalClient"]);
+ // Verify that the isMaster reply has the expected internalClient data.
+ ASSERT_FALSE(isMasterHandshake.request["internalClient"]);
// Verify that the ping op is counted as a success.
auto res = deferred.get();
ASSERT(res.elapsed);
@@ -978,31 +939,6 @@ TEST_F(NetworkInterfaceTest, TearDownWaitsForInProgress) {
ASSERT_EQ(getInProgress(), 0);
}
-TEST_F(NetworkInterfaceTest, RunCommandOnLeasedStream) {
- auto cs = fixture();
- auto target = cs.getServers().front();
- auto leasedStream = net().leaseStream(target, transport::kGlobalSSLMode, kNoTimeout).get();
- auto* client = leasedStream->getClient();
-
- auto request = RemoteCommandRequest(target, "admin", makeEchoCmdObj(), nullptr, kNoTimeout);
- auto deferred = client->runCommandRequest(request);
-
- auto res = deferred.get();
-
- ASSERT(res.elapsed);
- uassertStatusOK(res.status);
- leasedStream->indicateSuccess();
- leasedStream->indicateUsed();
-
- // This opmsg request expect the following reply, which is generated below
- // { echo: { echo: 1, foo: "bar", $db: "admin" }, ok: 1.0 }
- auto cmdObj = res.data.getObjectField("echo");
- ASSERT_EQ(1, cmdObj.getIntField("echo"));
- ASSERT_EQ("bar"_sd, cmdObj.getStringField("foo"));
- ASSERT_EQ("admin"_sd, cmdObj.getStringField("$db"));
- ASSERT_EQ(1, res.data.getIntField("ok"));
-}
-
} // namespace
} // namespace executor
} // namespace mongo