diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2020-03-02 22:11:36 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-03 03:29:45 +0000 |
commit | 6580304d0211f406566514ec68d5865a6a9e7810 (patch) | |
tree | 22b9d1710b387e9e880f96a26b4315c6f52ed049 /src/mongo/db/repl/vote_requester_test.cpp | |
parent | 33ba055bad586903038902825c14948038ad495e (diff) | |
download | mongo-6580304d0211f406566514ec68d5865a6a9e7810.tar.gz |
SERVER-46219 Unittests should log with JSON format
Diffstat (limited to 'src/mongo/db/repl/vote_requester_test.cpp')
-rw-r--r-- | src/mongo/db/repl/vote_requester_test.cpp | 124 |
1 files changed, 104 insertions, 20 deletions
diff --git a/src/mongo/db/repl/vote_requester_test.cpp b/src/mongo/db/repl/vote_requester_test.cpp index 94ba342ca11..b5155003603 100644 --- a/src/mongo/db/repl/vote_requester_test.cpp +++ b/src/mongo/db/repl/vote_requester_test.cpp @@ -284,7 +284,13 @@ TEST_F(VoteRequesterTest, VoterFailedToStoreLastVote) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedYesStatusNotOkBecauseFailedToStoreLastVote()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received an invalid response from host1:27017")); + + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "received an invalid response" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -297,7 +303,11 @@ TEST_F(VoteRequesterTest, BadConfigVersionWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseConfigVersionDoesNotMatch()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -310,7 +320,11 @@ TEST_F(VoteRequesterTest, SetNameDiffersWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -323,7 +337,12 @@ TEST_F(VoteRequesterTest, LastOpTimeIsGreaterWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); + processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -336,7 +355,13 @@ TEST_F(VoteRequesterTest, FailedToContactWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), badRemoteCommandResponse()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host1:27017")); + + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "failed to receive response" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -349,7 +374,11 @@ TEST_F(VoteRequesterTest, AlreadyVotedWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseAlreadyVoted()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -361,7 +390,11 @@ TEST_F(VoteRequesterTest, StaleTermLoseElection) { startCapturingLogMessages(); ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseTermIsGreater()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kStaleTerm == getResult()); ASSERT_EQUALS(1, getNumResponders()); @@ -373,9 +406,19 @@ TEST_F(VoteRequesterTest, NotEnoughVotesLoseElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), badRemoteCommandResponse()); - ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host2:27017")); + + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "failed to receive response" + << "from" + << "host2:27017")))); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kInsufficientVotes == getResult()); ASSERT_EQUALS(1, getNumResponders()); @@ -387,9 +430,18 @@ TEST_F(VoteRequesterTest, CallbackCanceledNotEnoughVotesLoseElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseAlreadyVoted()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), callbackCanceledCommandResponse()); - ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host2:27017")); + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "failed to receive response" + << "from" + << "host2:27017")))); // Make sure processing the callbackCanceled Response was necessary to get sufficient responses. ASSERT_TRUE(hasReceivedSufficientResponses()); // Because of the CallbackCanceled Response, host2 doesn't count as a responder. @@ -411,7 +463,11 @@ TEST_F(VoteRequesterDryRunTest, BadConfigVersionWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseConfigVersionDoesNotMatch()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -424,7 +480,11 @@ TEST_F(VoteRequesterDryRunTest, SetNameDiffersWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -437,7 +497,11 @@ TEST_F(VoteRequesterDryRunTest, LastOpTimeIsGreaterWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -450,7 +514,6 @@ TEST_F(VoteRequesterDryRunTest, FailedToContactWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), badRemoteCommandResponse()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host1:27017")); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -463,7 +526,11 @@ TEST_F(VoteRequesterDryRunTest, AlreadyVotedWinElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseAlreadyVoted()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), votedYes()); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kSuccessfullyElected == getResult()); @@ -475,7 +542,11 @@ TEST_F(VoteRequesterDryRunTest, StaleTermLoseElection) { startCapturingLogMessages(); ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseTermIsGreater()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kStaleTerm == getResult()); ASSERT_EQUALS(1, getNumResponders()); @@ -487,9 +558,18 @@ TEST_F(VoteRequesterDryRunTest, NotEnoughVotesLoseElection) { ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseSetNameDiffers()); ASSERT_FALSE(hasReceivedSufficientResponses()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); processResponse(requestFrom("host2"), badRemoteCommandResponse()); - ASSERT_EQUALS(1, countLogLinesContaining("failed to receive response from host2:27017")); + ASSERT_EQUALS( + 1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("failReason" + << "failed to receive response" + << "from" + << "host2:27017")))); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kInsufficientVotes == getResult()); ASSERT_EQUALS(1, getNumResponders()); @@ -532,7 +612,11 @@ TEST_F(VoteRequesterCatchupTakeoverDryRunTest, CatchupTakeoverPrimarySaysNoLoseE ASSERT_FALSE(hasReceivedSufficientResponses()); processResponse(requestFrom("host1"), votedNoBecauseLastOpTimeIsGreater()); - ASSERT_EQUALS(1, countLogLinesContaining("received a no vote from host1:27017")); + ASSERT_EQUALS(1, + countBSONFormatLogLinesIsSubset(BSON("attr" << BSON("vote" + << "no" + << "from" + << "host1:27017")))); ASSERT_TRUE(hasReceivedSufficientResponses()); ASSERT(VoteRequester::Result::kPrimaryRespondedNo == getResult()); ASSERT_EQUALS(3, getNumResponders()); |