summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/initial_syncer_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/initial_syncer_test.cpp')
-rw-r--r--src/mongo/db/repl/initial_syncer_test.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp
index cb1dccafaa7..3895f10fe3f 100644
--- a/src/mongo/db/repl/initial_syncer_test.cpp
+++ b/src/mongo/db/repl/initial_syncer_test.cpp
@@ -332,7 +332,7 @@ protected:
options.getMyLastOptime = [this]() { return _myLastOpTime; };
options.setMyLastOptime = [this](const OpTime& opTime) { _setMyLastOptime(opTime); };
options.resetOptimes = [this]() { _setMyLastOptime(OpTime()); };
- options.getSlaveDelay = [this]() { return Seconds(0); };
+ options.getSlaveDelay = []() { return Seconds(0); };
options.syncSourceSelector = this;
_options = options;
@@ -3588,4 +3588,66 @@ TEST_F(InitialSyncerTest, GetInitialSyncProgressReturnsCorrectProgress) {
<< attempt1;
}
+TEST_F(InitialSyncerTest, GetInitialSyncProgressOmitsClonerStatsIfClonerStatsExceedBsonLimit) {
+ auto initialSyncer = &getInitialSyncer();
+ auto opCtx = makeOpCtx();
+
+ _syncSourceSelector->setChooseNewSyncSourceResult_forTest(HostAndPort("localhost", 27017));
+ ASSERT_OK(initialSyncer->startup(opCtx.get(), 2U));
+
+ const std::size_t numCollections = 200000U;
+
+ auto net = getNet();
+ int baseRollbackId = 1;
+ {
+ executor::NetworkInterfaceMock::InNetworkGuard guard(net);
+
+ // Base rollback ID.
+ net->scheduleSuccessfulResponse(makeRollbackCheckerResponse(baseRollbackId));
+ net->runReadyNetworkOperations();
+
+ // Last oplog entry.
+ processSuccessfulLastOplogEntryFetcherResponse({makeOplogEntry(1)});
+
+ // Ignore oplog tailing query.
+ auto noi = net->getNextReadyRequest();
+ auto request = noi->getRequest();
+ assertRemoteCommandNameEquals("find", request);
+ ASSERT_TRUE(request.cmdObj.getBoolField("oplogReplay"));
+ net->blackHole(noi);
+
+ // listDatabases
+ NamespaceString nss("a.a");
+ request = net->scheduleSuccessfulResponse(makeListDatabasesResponse({nss.db().toString()}));
+ assertRemoteCommandNameEquals("listDatabases", request);
+ net->runReadyNetworkOperations();
+
+ // listCollections for "a"
+ std::vector<BSONObj> collectionInfos;
+ for (std::size_t i = 0; i < numCollections; ++i) {
+ const std::string collName = str::stream() << "coll-" << i;
+ collectionInfos.push_back(BSON("name" << collName << "options" << BSONObj()));
+ }
+ request = net->scheduleSuccessfulResponse(
+ makeCursorResponse(0LL, NamespaceString(nss.getCommandNS()), collectionInfos));
+ assertRemoteCommandNameEquals("listCollections", request);
+ net->runReadyNetworkOperations();
+ }
+
+ // This returns a valid document because we omit the cloner stats when they do not fit in a
+ // BSON document.
+ auto progress = initialSyncer->getInitialSyncProgress();
+ ASSERT_EQUALS(progress["initialSyncStart"].type(), Date) << progress;
+ ASSERT_FALSE(progress.hasField("databases")) << progress;
+
+ // Initial sync will attempt to log stats again at shutdown in a callback, where it should not
+ // terminate because we now return a valid stats document.
+ ASSERT_OK(initialSyncer->shutdown());
+
+ // Deliver cancellation signal to callbacks.
+ executor::NetworkInterfaceMock::InNetworkGuard(net)->runReadyNetworkOperations();
+
+ initialSyncer->join();
+}
+
} // namespace