diff options
Diffstat (limited to 'src/mongo/db/repl/vote_requester_test.cpp')
-rw-r--r-- | src/mongo/db/repl/vote_requester_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp index 463d532759d..48c401dd876 100644 --- a/src/mongo/db/repl/vote_requester_test.cpp +++ b/src/mongo/db/repl/vote_requester_test.cpp @@ -651,6 +651,37 @@ TEST_F(VoteRequesterCatchupTakeoverDryRunTest, CatchupTakeoverPrimarySaysNoLoseE stopCapturingLogMessages(); } +TEST_F(VoteRequesterCatchupTakeoverDryRunTest, + CatchupTakeoverAllNodesRespondedMeansSufficientResponses) { + startCapturingLogMessages(); + ASSERT_FALSE(hasReceivedSufficientResponses()); + + // Getting a good response from the other secondaries is insufficient. + processResponse(requestFrom("host2"), votedYes()); + processResponse(requestFrom("host3"), votedYes()); + processResponse(requestFrom("host4"), votedYes()); + ASSERT_FALSE(hasReceivedSufficientResponses()); + + // Getting a bad response from the primary means all targets have responded, and so we have + // received sufficient responses. + processResponse(requestFrom("host1"), badRemoteCommandResponse()); + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "failed to receive response" + << "from" + << "host1:27017")))); + ASSERT_TRUE(hasReceivedSufficientResponses()); + + // A bad response from the primary is equivalent to it saying NO. + ASSERT(VoteRequester::Result::kPrimaryRespondedNo == getResult()); + + // Only the secondaries are counted; the primary is excluded from the responders since it gave a + // bad response. + ASSERT_EQUALS(3, getNumResponders()); + stopCapturingLogMessages(); +} + } // namespace } // namespace repl } // namespace mongo |