summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2020-03-24 18:06:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-25 22:56:39 +0000
commit5e09c77c4c3bc394b7a8e21b57860a0e788d8b18 (patch)
tree8782814faf6c3ef0fcc97ff4c1ccd1849c9098aa
parentaa53e875ab30626a95bda04200d315b98bfadec4 (diff)
downloadmongo-5e09c77c4c3bc394b7a8e21b57860a0e788d8b18.tar.gz
SERVER-46434 added more MemberConfig::toBSON unittests
-rw-r--r--src/mongo/db/repl/member_config_test.cpp82
1 files changed, 78 insertions, 4 deletions
diff --git a/src/mongo/db/repl/member_config_test.cpp b/src/mongo/db/repl/member_config_test.cpp
index 80588301897..028af9c5ed5 100644
--- a/src/mongo/db/repl/member_config_test.cpp
+++ b/src/mongo/db/repl/member_config_test.cpp
@@ -228,14 +228,14 @@ TEST(MemberConfig, ParseAndSetNewlyAddedField) {
ASSERT_FALSE(mc.isNewlyAdded());
mc.setNewlyAdded(true);
- ASSERT_TRUE(mc.isNewlyAdded().get());
+ ASSERT_TRUE(mc.isNewlyAdded());
}
{
MemberConfig mc(BSON("_id" << 0 << "host"
<< "h"
<< "newlyAdded" << true),
&tagConfig);
- ASSERT_TRUE(mc.isNewlyAdded().get());
+ ASSERT_TRUE(mc.isNewlyAdded());
}
}
@@ -253,7 +253,7 @@ TEST(MemberConfig, NewlyAddedSetToFalseShouldThrow) {
ExceptionFor<ErrorCodes::InvalidReplicaSetConfig>);
}
-TEST(MemberConfig, VotingNodeWithNewlyAddedFieldShouldStillHaveVote) {
+TEST(MemberConfig, VotingNodeWithNewlyAddedFieldShouldStillHaveVoteAfterToBSON) {
// Set the flag to add the 'newlyAdded' field to MemberConfigs.
enableAutomaticReconfig = true;
// Set the flag back to false after this test exits.
@@ -266,16 +266,90 @@ TEST(MemberConfig, VotingNodeWithNewlyAddedFieldShouldStillHaveVote) {
<< "h"
<< "newlyAdded" << true),
&tagConfig);
- ASSERT_TRUE(mc.isNewlyAdded().get());
+ ASSERT_TRUE(mc.isNewlyAdded());
// Nodes with newly added field set should transiently not be allowed to vote.
ASSERT_FALSE(mc.isVoter());
+ ASSERT_EQ(0, mc.getNumVotes());
// Verify that the member is still a voting node.
const auto obj = mc.toBSON(tagConfig);
long long votes;
uassertStatusOK(bsonExtractIntegerField(obj, "votes", &votes));
ASSERT_EQ(1, votes);
+
+ MemberConfig mc2(obj, &tagConfig);
+ ASSERT_TRUE(mc2.isNewlyAdded());
+ ASSERT_FALSE(mc2.isVoter());
+ ASSERT_EQ(0, mc2.getNumVotes());
+}
+
+TEST(MemberConfig, NonVotingNodesWithNewlyAddedFieldShouldStillHaveZeroVotesAfterToBSON) {
+ // Set the flag to add the 'newlyAdded' field to MemberConfigs.
+ enableAutomaticReconfig = true;
+ // Set the flag back to false after this test exits.
+ ON_BLOCK_EXIT([] { enableAutomaticReconfig = false; });
+
+ ReplSetTagConfig tagConfig;
+
+ MemberConfig mc(BSON("_id" << 0 << "host"
+ << "h"
+ << "votes" << 0 << "priority" << 0 << "newlyAdded" << true),
+ &tagConfig);
+ ASSERT_TRUE(mc.isNewlyAdded());
+ ASSERT_FALSE(mc.isVoter());
+ ASSERT_EQ(0, mc.getNumVotes());
+
+ const auto obj = mc.toBSON(tagConfig);
+ long long votes;
+ uassertStatusOK(bsonExtractIntegerField(obj, "votes", &votes));
+ ASSERT_EQ(0, votes);
+
+ MemberConfig mc2(obj, &tagConfig);
+ ASSERT_TRUE(mc2.isNewlyAdded());
+ ASSERT_FALSE(mc2.isVoter());
+ ASSERT_EQ(0, mc2.getNumVotes());
+}
+
+TEST(MemberConfig, NonVotingNodesShouldStillHaveZeroVotesAfterToBSON) {
+ ReplSetTagConfig tagConfig;
+ MemberConfig mc(BSON("_id" << 0 << "host"
+ << "h"
+ << "votes" << 0 << "priority" << 0),
+ &tagConfig);
+ ASSERT_FALSE(mc.isNewlyAdded());
+ ASSERT_FALSE(mc.isVoter());
+ ASSERT_EQ(0, mc.getNumVotes());
+
+ const auto obj = mc.toBSON(tagConfig);
+ long long votes;
+ uassertStatusOK(bsonExtractIntegerField(obj, "votes", &votes));
+ ASSERT_EQ(0, votes);
+
+ MemberConfig mc2(obj, &tagConfig);
+ ASSERT_FALSE(mc2.isNewlyAdded());
+ ASSERT_FALSE(mc2.isVoter());
+ ASSERT_EQ(0, mc2.getNumVotes());
+}
+
+TEST(MemberConfig, VotingNodesShouldStillHaveVoteAfterToBSON) {
+ ReplSetTagConfig tagConfig;
+ MemberConfig mc(BSON("_id" << 0 << "host"
+ << "h"),
+ &tagConfig);
+ ASSERT_FALSE(mc.isNewlyAdded());
+ ASSERT_TRUE(mc.isVoter());
+ ASSERT_EQ(1, mc.getNumVotes());
+
+ const auto obj = mc.toBSON(tagConfig);
+ long long votes;
+ uassertStatusOK(bsonExtractIntegerField(obj, "votes", &votes));
+ ASSERT_EQ(1, votes);
+
+ MemberConfig mc2(obj, &tagConfig);
+ ASSERT_FALSE(mc2.isNewlyAdded());
+ ASSERT_TRUE(mc2.isVoter());
+ ASSERT_EQ(1, mc2.getNumVotes());
}
TEST(MemberConfig, ParseHidden) {