summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/replication_coordinator_test_fixture.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
index dd5ab79873d..1e7f8f07e71 100644
--- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
+++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
@@ -277,7 +277,10 @@ void ReplCoordTest::simulateSuccessfulV1Election() {
ReplicaSetConfig rsConfig = replCoord->getReplicaSetConfig_forTest();
ASSERT(replCoord->getMemberState().secondary()) << replCoord->getMemberState().toString();
- while (!replCoord->getMemberState().primary()) {
+ bool hasReadyRequests = true;
+ // Process requests until we're primary and consume the heartbeats for the notification
+ // of election win.
+ while (!replCoord->getMemberState().primary() || hasReadyRequests) {
log() << "Waiting on network in state " << replCoord->getMemberState();
getNet()->enterNetwork();
if (net->now() < electionTimeoutWhen) {
@@ -314,6 +317,7 @@ void ReplCoordTest::simulateSuccessfulV1Election() {
net->blackHole(noi);
}
net->runReadyNetworkOperations();
+ hasReadyRequests = net->hasReadyRequests();
getNet()->exitNetwork();
}
ASSERT(replCoord->isWaitingForApplierToDrain());
@@ -329,11 +333,6 @@ void ReplCoordTest::simulateSuccessfulV1Election() {
ASSERT_FALSE(imResponse.isSecondary()) << imResponse.toBSON().toString();
ASSERT(replCoord->getMemberState().primary()) << replCoord->getMemberState().toString();
-
- // Consume the notification of election win.
- for (int i = 0; i < rsConfig.getNumMembers() - 1; i++) {
- replyToReceivedHeartbeatV1();
- }
}
void ReplCoordTest::simulateSuccessfulElection() {
@@ -342,7 +341,10 @@ void ReplCoordTest::simulateSuccessfulElection() {
NetworkInterfaceMock* net = getNet();
ReplicaSetConfig rsConfig = replCoord->getReplicaSetConfig_forTest();
ASSERT(replCoord->getMemberState().secondary()) << replCoord->getMemberState().toString();
- while (!replCoord->getMemberState().primary()) {
+ bool hasReadyRequests = true;
+ // Process requests until we're primary and consume the heartbeats for the notification
+ // of election win.
+ while (!replCoord->getMemberState().primary() || hasReadyRequests) {
log() << "Waiting on network in state " << replCoord->getMemberState();
getNet()->enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
@@ -375,6 +377,7 @@ void ReplCoordTest::simulateSuccessfulElection() {
net->blackHole(noi);
}
net->runReadyNetworkOperations();
+ hasReadyRequests = net->hasReadyRequests();
getNet()->exitNetwork();
}
ASSERT(replCoord->isWaitingForApplierToDrain());
@@ -390,11 +393,6 @@ void ReplCoordTest::simulateSuccessfulElection() {
ASSERT_FALSE(imResponse.isSecondary()) << imResponse.toBSON().toString();
ASSERT(replCoord->getMemberState().primary()) << replCoord->getMemberState().toString();
-
- // Consume the notification of election win.
- for (int i = 0; i < rsConfig.getNumMembers() - 1; i++) {
- replyToReceivedHeartbeat();
- }
}
void ReplCoordTest::shutdown() {