summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/repl_set_config_test.cpp
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2020-03-26 08:46:08 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-02 12:14:43 +0000
commitb040399238a9450ac1713c5cf7269145074d1fab (patch)
tree486b557532bc8d86fab3dc808c0d3e7494f43c56 /src/mongo/db/repl/repl_set_config_test.cpp
parentd2789d7e75be524212b8b6ab213577c69632fbfd (diff)
downloadmongo-b040399238a9450ac1713c5cf7269145074d1fab.tar.gz
SERVER-46345 Remove newlyAdded field on heartbeats that indicate a node left initial sync
Diffstat (limited to 'src/mongo/db/repl/repl_set_config_test.cpp')
-rw-r--r--src/mongo/db/repl/repl_set_config_test.cpp88
1 files changed, 73 insertions, 15 deletions
diff --git a/src/mongo/db/repl/repl_set_config_test.cpp b/src/mongo/db/repl/repl_set_config_test.cpp
index db6cbecaabc..e088108c723 100644
--- a/src/mongo/db/repl/repl_set_config_test.cpp
+++ b/src/mongo/db/repl/repl_set_config_test.cpp
@@ -912,13 +912,84 @@ TEST(ReplSetConfig, SetNewlyAddedFieldForMemberConfig) {
<< "rs0"
<< "version" << 1 << "protocolVersion" << 1 << "members"
<< BSON_ARRAY(BSON("_id" << 1 << "host"
- << "localhost:12345")))));
+ << "n1:1")
+ << BSON("_id" << 2 << "host"
+ << "n2:1")))));
// The member should have its 'newlyAdded' field set to false by default.
ASSERT_FALSE(config.findMemberByID(1)->isNewlyAdded());
+ ASSERT_EQ(2, config.getTotalVotingMembers());
+ ASSERT_EQ(2, config.getMajorityVoteCount());
+ ASSERT_EQ(2, config.getWriteMajority());
+ ASSERT_EQ(2, config.getWritableVotingMembersCount());
+
+ {
+ auto modeSW = config.findCustomWriteMode("$majority");
+ ASSERT(modeSW.isOK());
+ auto modeIt = modeSW.getValue().constraintsBegin();
+ ASSERT_EQ(modeIt->getMinCount(), 2);
+ }
+
+ config.addNewlyAddedFieldForMember(MemberId(1));
+
+ ASSERT_TRUE(config.findMemberByID(1)->isNewlyAdded());
+ ASSERT_EQ(1, config.getTotalVotingMembers());
+ ASSERT_EQ(1, config.getMajorityVoteCount());
+ ASSERT_EQ(1, config.getWriteMajority());
+ ASSERT_EQ(1, config.getWritableVotingMembersCount());
+
+ {
+ auto modeSW = config.findCustomWriteMode("$majority");
+ ASSERT(modeSW.isOK());
+ auto modeIt = modeSW.getValue().constraintsBegin();
+ ASSERT_EQ(modeIt->getMinCount(), 1);
+ }
+}
+
+TEST(ReplSetConfig, RemoveNewlyAddedFieldForMemberConfig) {
+ // 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; });
+
+ ReplSetConfig config;
+ ASSERT_OK(config.initialize(BSON("_id"
+ << "rs0"
+ << "version" << 1 << "protocolVersion" << 1 << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "n1:1"
+ << "newlyAdded" << true)
+ << BSON("_id" << 2 << "host"
+ << "n2:1")))));
+
- config.setNewlyAddedFieldForMemberAtIndex(0, true);
ASSERT_TRUE(config.findMemberByID(1)->isNewlyAdded());
+ ASSERT_EQ(1, config.getTotalVotingMembers());
+ ASSERT_EQ(1, config.getMajorityVoteCount());
+ ASSERT_EQ(1, config.getWriteMajority());
+ ASSERT_EQ(1, config.getWritableVotingMembersCount());
+
+ {
+ auto modeSW = config.findCustomWriteMode("$majority");
+ ASSERT(modeSW.isOK());
+ auto modeIt = modeSW.getValue().constraintsBegin();
+ ASSERT_EQ(modeIt->getMinCount(), 1);
+ }
+
+ config.removeNewlyAddedFieldForMember(MemberId(1));
+
+ ASSERT_FALSE(config.findMemberByID(1)->isNewlyAdded());
+ ASSERT_EQ(2, config.getTotalVotingMembers());
+ ASSERT_EQ(2, config.getMajorityVoteCount());
+ ASSERT_EQ(2, config.getWriteMajority());
+ ASSERT_EQ(2, config.getWritableVotingMembersCount());
+
+ {
+ auto modeSW = config.findCustomWriteMode("$majority");
+ ASSERT(modeSW.isOK());
+ auto modeIt = modeSW.getValue().constraintsBegin();
+ ASSERT_EQ(modeIt->getMinCount(), 2);
+ }
}
TEST(ReplSetConfig, ParsingNewlyAddedSetsFieldToTrueCorrectly) {
@@ -956,19 +1027,6 @@ TEST(ReplSetConfig, ParseFailsWithNewlyAddedSetToFalse) {
ASSERT_EQUALS(ErrorCodes::InvalidReplicaSetConfig, status);
}
-TEST(ReplSetConfig, CannotSetNewlyAddedFieldToFalseForMemberConfig) {
- ReplSetConfig config;
- ASSERT_OK(config.initialize(BSON("_id"
- << "rs0"
- << "version" << 1 << "protocolVersion" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "localhost:12345")))));
- // Cannot set 'newlyAdded' field to false.
- ASSERT_THROWS_CODE(config.setNewlyAddedFieldForMemberAtIndex(0, false),
- AssertionException,
- ErrorCodes::InvalidReplicaSetConfig);
-}
-
TEST(ReplSetConfig, NodeWithNewlyAddedFieldHasVotesZero) {
// Set the flag to add the 'newlyAdded' field to MemberConfigs.
enableAutomaticReconfig = true;