diff options
author | Benety Goh <benety@mongodb.com> | 2015-10-26 13:36:45 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-10-26 15:35:02 -0400 |
commit | 08bcdca185912cf9f8c6c6bf7faa94b23ea76583 (patch) | |
tree | 881e4dbcea7f534f1aeeac290506985b72561ceb | |
parent | 1c91d1a2b789fef8be6427de81c35658ff30009d (diff) | |
download | mongo-08bcdca185912cf9f8c6c6bf7faa94b23ea76583.tar.gz |
SERVER-20979 ensure election completes before running waitForMemberState and waitForDrainFinish
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index b2582d33946..7f5cbc9f17a 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -3323,12 +3323,18 @@ TEST_F(ReplCoordTest, WaitForMemberState) { << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); - auto replCoord = this->getReplCoord(); + auto replCoord = getReplCoord(); + auto initialTerm = replCoord->getTerm(); replCoord->setMyLastOptime(OpTime(Timestamp(1, 0), 0)); ASSERT_TRUE(replCoord->setFollowerMode(MemberState::RS_SECONDARY)); - // Single node cluster - this node should transition to PRIMARY from SECONDARY immediately. - auto timeout = Milliseconds(10); + // Successful dry run election increases term. + ASSERT_EQUALS(initialTerm + 1, replCoord->getTerm()); + + // Single node cluster - this node should start election on setFollowerMode() completion. + replCoord->waitForElectionFinish_forTest(); + + auto timeout = Milliseconds(1); ASSERT_OK(replCoord->waitForMemberState(MemberState::RS_PRIMARY, timeout)); ASSERT_EQUALS(ErrorCodes::ExceededTimeLimit, replCoord->waitForMemberState(MemberState::RS_REMOVED, timeout)); @@ -3351,12 +3357,18 @@ TEST_F(ReplCoordTest, WaitForDrainFinish) { << BSON_ARRAY(BSON("_id" << 0 << "host" << "test1:1234"))), HostAndPort("test1", 1234)); - auto replCoord = this->getReplCoord(); + auto replCoord = getReplCoord(); + auto initialTerm = replCoord->getTerm(); replCoord->setMyLastOptime(OpTime(Timestamp(1, 0), 0)); ASSERT_TRUE(replCoord->setFollowerMode(MemberState::RS_SECONDARY)); - // Single node cluster - this node should transition to PRIMARY from SECONDARY immediately. - auto timeout = Milliseconds(10); + // Successful dry run election increases term. + ASSERT_EQUALS(initialTerm + 1, replCoord->getTerm()); + + // Single node cluster - this node should start election on setFollowerMode() completion. + replCoord->waitForElectionFinish_forTest(); + + auto timeout = Milliseconds(1); ASSERT_OK(replCoord->waitForMemberState(MemberState::RS_PRIMARY, timeout)); ASSERT_TRUE(replCoord->isWaitingForApplierToDrain()); |