diff options
Diffstat (limited to 'src/mongo/db/repl/check_quorum_for_config_change_test.cpp')
-rw-r--r-- | src/mongo/db/repl/check_quorum_for_config_change_test.cpp | 241 |
1 files changed, 82 insertions, 159 deletions
diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp index 4658863cb0c..5bb4fefbc08 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp @@ -48,18 +48,18 @@ #include "mongo/unittest/unittest.h" #include "mongo/util/net/hostandport.h" -#define ASSERT_REASON_CONTAINS(STATUS, PATTERN) \ - do { \ - const mongo::Status s_ = (STATUS); \ - ASSERT_FALSE(s_.reason().find(PATTERN) == std::string::npos) << #STATUS ".reason() == " \ - << s_.reason(); \ +#define ASSERT_REASON_CONTAINS(STATUS, PATTERN) \ + do { \ + const mongo::Status s_ = (STATUS); \ + ASSERT_FALSE(s_.reason().find(PATTERN) == std::string::npos) \ + << #STATUS ".reason() == " << s_.reason(); \ } while (false) -#define ASSERT_NOT_REASON_CONTAINS(STATUS, PATTERN) \ - do { \ - const mongo::Status s_ = (STATUS); \ - ASSERT_TRUE(s_.reason().find(PATTERN) == std::string::npos) << #STATUS ".reason() == " \ - << s_.reason(); \ +#define ASSERT_NOT_REASON_CONTAINS(STATUS, PATTERN) \ + do { \ + const mongo::Status s_ = (STATUS); \ + ASSERT_TRUE(s_.reason().find(PATTERN) == std::string::npos) \ + << #STATUS ".reason() == " << s_.reason(); \ } while (false) namespace mongo { @@ -141,30 +141,24 @@ ReplSetConfig assertMakeRSConfig(const BSONObj& configBson) { } TEST_F(CheckQuorumForInitiate, ValidSingleNodeSet) { - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1")))); startQuorumCheck(config, 0); ASSERT_OK(waitForQuorumCheck()); } TEST_F(CheckQuorumForInitiate, QuorumCheckCanceledByShutdown) { getExecutor().shutdown(); - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1")))); startQuorumCheck(config, 0); ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, waitForQuorumCheck()); } @@ -173,23 +167,20 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSeveralDownNodes) { // In this test, "we" are host "h3:1". All other nodes time out on // their heartbeat request, and so the quorum check for initiate // will fail because some members were unavailable. - ReplSetConfig config = assertMakeRSConfig(BSON("_id" - << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1:1") - << BSON("_id" << 2 << "host" - << "h2:1") - << BSON("_id" << 3 << "host" - << "h3:1") - << BSON("_id" << 4 << "host" - << "h4:1") - << BSON("_id" << 5 << "host" - << "h5:1")))); + ReplSetConfig config = + assertMakeRSConfig(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1:1") + << BSON("_id" << 2 << "host" + << "h2:1") + << BSON("_id" << 3 << "host" + << "h3:1") + << BSON("_id" << 4 << "host" + << "h4:1") + << BSON("_id" << 5 << "host" + << "h5:1")))); startQuorumCheck(config, 2); getNet()->enterNetwork(); const Date_t startDate = getNet()->now(); @@ -255,11 +246,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckSuccessForFiveNodes) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -283,8 +270,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckSuccessForFiveNodes) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); getNet()->scheduleResponse( noi, startDate + Milliseconds(10), makeHeartbeatResponse(rsConfig, Milliseconds(8))); } @@ -302,19 +289,12 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToOneDownNode) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" << "h2:1" - << "priority" - << 0 - << "votes" - << 0) + << "priority" << 0 << "votes" << 0) << BSON("_id" << 3 << "host" << "h3:1") << BSON("_id" << 4 << "host" @@ -336,8 +316,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToOneDownNode) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse( noi, startDate + Milliseconds(10), {ErrorCodes::NoSuchKey, "No response"}); @@ -369,11 +349,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -397,8 +373,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h4", 1)) { getNet()->scheduleResponse( noi, @@ -434,11 +410,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -449,8 +421,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { << "h4:1") << BSON("_id" << 5 << "host" << "h5:1")) - << "settings" - << BSON("replicaSetId" << replicaSetId))); + << "settings" << BSON("replicaSetId" << replicaSetId))); const int myConfigIndex = 2; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -467,8 +438,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); ASSERT_BSONOBJ_EQ(BSON(rpc::kReplSetMetadataFieldName << 1), request.metadata); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == incompatibleHost) { OpTime opTime{Timestamp{10, 10}, 10}; Date_t wallTime = Date_t(); @@ -499,10 +470,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { ASSERT_EQUALS(ErrorCodes::NewReplicaSetConfigurationIncompatible, status); ASSERT_REASON_CONTAINS(status, str::stream() << "Our replica set ID of " << replicaSetId - << " did not match that of " - << incompatibleHost.toString() - << ", which is " - << unexpectedId); + << " did not match that of " << incompatibleHost.toString() + << ", which is " << unexpectedId); ASSERT_NOT_REASON_CONTAINS(status, "h1:1"); ASSERT_NOT_REASON_CONTAINS(status, "h2:1"); ASSERT_NOT_REASON_CONTAINS(status, "h3:1"); @@ -518,11 +487,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNode) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -546,8 +511,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNode) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { long long configVersion = 1; getNet()->scheduleResponse( @@ -582,11 +547,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNodeOnlyOneRespo const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 1 - << "protocolVersion" - << 1 - << "members" + << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -610,8 +571,8 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNodeOnlyOneRespo const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { long long configVersion = 1; getNet()->scheduleResponse( @@ -642,11 +603,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToHigherConfigVersion) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -666,8 +623,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToHigherConfigVersion) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1)) { long long configVersion = 5; getNet()->scheduleResponse( @@ -696,11 +653,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -720,8 +673,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse( noi, @@ -754,11 +707,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -767,16 +716,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "votes" - << 0 - << "priority" - << 0)))); + << "votes" << 0 << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -790,8 +733,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToInsufficientVoters) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1) || request.target == HostAndPort("h5", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -820,11 +763,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -833,12 +772,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "priority" - << 0) + << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "priority" - << 0)))); + << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -852,8 +789,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckFailsDueToNoElectableNodeResponding) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h5", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -878,11 +815,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -891,16 +824,10 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { << "h3:1") << BSON("_id" << 4 << "host" << "h4:1" - << "votes" - << 0 - << "priority" - << 0) + << "votes" << 0 << "priority" << 0) << BSON("_id" << 5 << "host" << "h5:1" - << "votes" - << 0 - << "priority" - << 0)))); + << "votes" << 0 << "priority" << 0)))); const int myConfigIndex = 3; const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex); @@ -914,8 +841,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckSucceedsWithAsSoonAsPossible) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1) || request.target == HostAndPort("h2", 1)) { getNet()->scheduleResponse(noi, startDate + Milliseconds(10), @@ -938,11 +865,7 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckProcessesCallbackCanceledResponse) { const ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id" << "rs0" - << "version" - << 2 - << "protocolVersion" - << 1 - << "members" + << "version" << 2 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1:1") << BSON("_id" << 2 << "host" @@ -962,8 +885,8 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckProcessesCallbackCanceledResponse) { const RemoteCommandRequest& request = noi->getRequest(); ASSERT_EQUALS("admin", request.dbname); ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj); - ASSERT(seenHosts.insert(request.target).second) << "Already saw " - << request.target.toString(); + ASSERT(seenHosts.insert(request.target).second) + << "Already saw " << request.target.toString(); if (request.target == HostAndPort("h1", 1)) { getNet()->scheduleResponse( noi, |