summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-02-10 11:36:06 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-10 22:39:39 +0000
commit09295d5476f3f5163abe0597128afc0e8f0b04ca (patch)
tree1ac5c417ee695478ad3ac1059859b34c554ca505 /src/mongo
parent6598a19df0d9f35c4f4cc9524daaf5e32bb63272 (diff)
downloadmongo-09295d5476f3f5163abe0597128afc0e8f0b04ca.tar.gz
SERVER-46054: Test getMore empty batch for NewOplogFetcher
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp5
-rw-r--r--src/mongo/db/repl/oplog_fetcher_test.cpp34
2 files changed, 36 insertions, 3 deletions
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index bc23fa0d029..087bb34bbaa 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -959,9 +959,8 @@ StatusWith<NewOplogFetcher::Documents> NewOplogFetcher::_getNextBatch() {
// The 'find' command has already been executed, so reset the socket timeout to reflect
// the awaitData timeout with a network buffer.
_setSocketTimeout(durationCount<Milliseconds>(_awaitDataTimeout));
- } else if (!_cursor->more()) {
- // The only reason more() should return false is if the cursor is dead.
- invariant(_cursor->isDead());
+ } else {
+ _cursor->more();
}
while (_cursor->moreInCurrentBatch()) {
diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp
index 172f4d6c182..ed5c69a4b0f 100644
--- a/src/mongo/db/repl/oplog_fetcher_test.cpp
+++ b/src/mongo/db/repl/oplog_fetcher_test.cpp
@@ -1236,6 +1236,10 @@ void NewOplogFetcherTest::setUp() {
auto target = HostAndPort{"localhost:12346"};
_mockServer = std::make_unique<MockRemoteDBServer>(target.toString());
+
+ // Always enable oplogFetcherUsesExhaust at the beginning of each unittest in case some
+ // unittests disable it in the test.
+ oplogFetcherUsesExhaust = true;
}
std::unique_ptr<NewOplogFetcher> NewOplogFetcherTest::makeOplogFetcher() {
@@ -2687,4 +2691,34 @@ TEST_F(NewOplogFetcherTest, DisconnectsOnErrorsDuringExhaustStream) {
ASSERT_OK(shutdownState.getStatus());
}
+
+TEST_F(NewOplogFetcherTest, GetMoreEmptyBatch) {
+ ShutdownState shutdownState;
+
+ // Create an oplog fetcher without any retries.
+ auto oplogFetcher = getOplogFetcherAfterConnectionCreated(std::ref(shutdownState));
+
+ CursorId cursorId = 22LL;
+ auto firstEntry = makeNoopOplogEntry(lastFetched);
+ auto metadataObj = makeOplogBatchMetadata(boost::none, staleOqMetadata);
+
+ auto conn = oplogFetcher->getDBClientConnection_forTest();
+
+ // Creating the cursor will succeed.
+ auto m =
+ processSingleRequestResponse(conn, makeFirstBatch(cursorId, {firstEntry}, metadataObj));
+
+ // Empty batch from first getMore.
+ processSingleRequestResponse(
+ conn, makeSubsequentBatch(cursorId, {}, metadataObj, true /* moreToCome */));
+
+ // Terminating empty batch from exhaust stream with cursorId 0.
+ processSingleExhaustResponse(oplogFetcher->getDBClientConnection_forTest(),
+ makeSubsequentBatch(0LL, {}, metadataObj, false /* moreToCome */),
+ false);
+
+ oplogFetcher->join();
+
+ ASSERT_OK(shutdownState.getStatus());
+}
} // namespace