diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2016-04-15 14:53:45 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2016-04-15 17:23:56 -0400 |
commit | 04f48bd5ae704d3a8df8bf7b8864d7258f4241e3 (patch) | |
tree | a47bf1e05a250d237bfca0861e3ce7778617ee9b /src | |
parent | a25105bd6ef95a24eda040e1f75c0371b00c4a50 (diff) | |
download | mongo-04f48bd5ae704d3a8df8bf7b8864d7258f4241e3.tar.gz |
SERVER-22995 Fix synchronization of DBWorker in unittests.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_test_fixture.cpp | 22 |
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() { |