summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2020-04-14 18:03:21 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-01 02:49:37 +0000
commit5d32cf67738d377070c5ab0e44a267d4b3b3b7bb (patch)
tree1476452753fbfc24f9564ce9108cb9ef0098a496 /src/mongo/db/repl
parent6a5e183833f49e3d5ec7ed54da4bf5471b63ec8d (diff)
downloadmongo-5d32cf67738d377070c5ab0e44a267d4b3b3b7bb.tar.gz
SERVER-47418 deploy unittest::MinimumLoggedSeverityGuard to all tests
(cherry picked from commit e4794531419bff51da233bc4453db6f99d1809ff)
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/apply_ops_test.cpp9
-rw-r--r--src/mongo/db/repl/cloner_test_fixture.cpp4
-rw-r--r--src/mongo/db/repl/cloner_test_fixture.h6
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp6
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp19
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp11
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp8
-rw-r--r--src/mongo/db/repl/replication_coordinator_test_fixture.cpp1
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.cpp4
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.h8
-rw-r--r--src/mongo/db/repl/topology_coordinator_v1_test.cpp13
11 files changed, 49 insertions, 40 deletions
diff --git a/src/mongo/db/repl/apply_ops_test.cpp b/src/mongo/db/repl/apply_ops_test.cpp
index 64b675c22e4..3d5026f54d4 100644
--- a/src/mongo/db/repl/apply_ops_test.cpp
+++ b/src/mongo/db/repl/apply_ops_test.cpp
@@ -82,6 +82,9 @@ private:
void tearDown() override;
protected:
+ // Reset default log level when each test is over in case it was changed.
+ unittest::MinimumLoggedSeverityGuard _verbosityGuard{logv2::LogComponent::kReplication};
+
OpObserverMock* _opObserver = nullptr;
std::unique_ptr<StorageInterface> _storage;
};
@@ -116,9 +119,6 @@ void ApplyOpsTest::tearDown() {
_storage = {};
_opObserver = nullptr;
- // Reset default log level in case it was changed.
- setMinimumLoggedSeverity(logv2::LogComponent::kReplication, logv2::LogSeverity::Debug(0));
-
ServiceContextMongoDTest::tearDown();
}
@@ -291,7 +291,8 @@ TEST_F(ApplyOpsTest, ApplyOpsPropagatesOplogApplicationMode) {
auto opCtx = cc().makeOperationContext();
// Increase log component verbosity to check for op application messages.
- setMinimumLoggedSeverity(logv2::LogComponent::kReplication, logv2::LogSeverity::Debug(3));
+ auto verbosityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kReplication,
+ logv2::LogSeverity::Debug(3)};
// Test that the 'applyOps' function passes the oplog application mode through correctly to the
// underlying op application functions.
diff --git a/src/mongo/db/repl/cloner_test_fixture.cpp b/src/mongo/db/repl/cloner_test_fixture.cpp
index de432238e4c..4ed5bb7d31c 100644
--- a/src/mongo/db/repl/cloner_test_fixture.cpp
+++ b/src/mongo/db/repl/cloner_test_fixture.cpp
@@ -57,8 +57,6 @@ BSONObj ClonerTestFixture::createCursorResponse(const std::string& nss, const BS
void ClonerTestFixture::setUp() {
unittest::Test::setUp();
- logger::globalLogDomain()->setMinimumLoggedSeverity(
- logger::LogComponent::kReplicationInitialSync, logger::LogSeverity::Debug(1));
Client::initThread("ClonerTest");
ThreadPool::Options options;
options.minThreads = 1U;
@@ -89,8 +87,6 @@ void ClonerTestFixture::setUp() {
void ClonerTestFixture::tearDown() {
_dbWorkThreadPool.reset();
Client::releaseCurrent();
- logger::globalLogDomain()->setMinimumLoggedSeverity(
- logger::LogComponent::kReplicationInitialSync, logger::LogSeverity::Debug(0));
unittest::Test::tearDown();
}
diff --git a/src/mongo/db/repl/cloner_test_fixture.h b/src/mongo/db/repl/cloner_test_fixture.h
index 6dddb4162da..8cbf4812fca 100644
--- a/src/mongo/db/repl/cloner_test_fixture.h
+++ b/src/mongo/db/repl/cloner_test_fixture.h
@@ -34,6 +34,9 @@
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/dbtests/mock/mock_dbclient_connection.h"
+#include "mongo/logv2/log_component.h"
+#include "mongo/logv2/log_severity.h"
+#include "mongo/unittest/log_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/concurrency/thread_pool.h"
@@ -69,6 +72,9 @@ protected:
private:
static constexpr int kInitialRollbackId = 1;
+
+ unittest::MinimumLoggedSeverityGuard _verboseGuard{logv2::LogComponent::kReplicationInitialSync,
+ logv2::LogSeverity::Debug(1)};
};
} // namespace repl
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
index 2a74373adc4..c3f64ef471b 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
@@ -581,7 +581,8 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
ASSERT_EQUALS(ErrorCodes::ConfigurationInProgress,
getReplCoord()->processReplSetReconfig(&opCtx, args, &result));
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(2));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(2)};
startCapturingLogMessages();
// receive sufficient heartbeats to allow the node to see a majority.
@@ -1191,7 +1192,8 @@ TEST_F(TakeoverTest, PrefersPriorityToCatchupTakeoverIfNodeHasHighestPriority) {
<< "node3:12345"))
<< "protocolVersion" << 1);
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(2));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(2)};
startCapturingLogMessages();
assertStartSuccess(configObj, HostAndPort("node1", 12345));
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
index ea55725ddc8..f74f211a5f0 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
@@ -87,7 +87,8 @@ ReplSetHeartbeatResponse ReplCoordHBV1Test::receiveHeartbeatFrom(const ReplSetCo
TEST_F(ReplCoordHBV1Test,
NodeJoinsExistingReplSetWhenReceivingAConfigContainingTheNodeViaHeartbeat) {
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -157,7 +158,6 @@ TEST_F(ReplCoordHBV1Test,
class ReplCoordHBV1ReconfigTest : public ReplCoordHBV1Test {
public:
void setUp() {
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
BSONObj configBson = BSON("_id"
<< "mySet"
<< "version" << initConfigVersion << "term" << initConfigTerm
@@ -190,6 +190,9 @@ public:
return assertMakeRSConfig(makeConfigObj(version, term));
}
+ unittest::MinimumLoggedSeverityGuard severityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
+
int initConfigVersion = 2;
int initConfigTerm = 2;
long long UninitializedTerm = OpTime::kUninitializedTerm;
@@ -498,7 +501,8 @@ TEST_F(ReplCoordHBV1Test, AwaitIsMasterReturnsResponseOnReconfigViaHeartbeat) {
ASSERT_EQUALS("node3", hosts[2].host());
});
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
ReplSetConfig rsConfig =
assertMakeRSConfig(BSON("_id"
<< "mySet"
@@ -549,7 +553,8 @@ TEST_F(ReplCoordHBV1Test, AwaitIsMasterReturnsResponseOnReconfigViaHeartbeat) {
TEST_F(ReplCoordHBV1Test,
ArbiterJoinsExistingReplSetWhenReceivingAConfigContainingTheArbiterViaHeartbeat) {
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
ReplSetConfig rsConfig =
assertMakeRSConfig(BSON("_id"
<< "mySet"
@@ -622,7 +627,8 @@ TEST_F(ReplCoordHBV1Test,
NodeDoesNotJoinExistingReplSetWhenReceivingAConfigNotContainingTheNodeViaHeartbeat) {
// Tests that a node in RS_STARTUP will not transition to RS_REMOVED if it receives a
// configuration that does not contain it.
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
ReplSetConfig rsConfig = assertMakeRSConfig(BSON("_id"
<< "mySet"
<< "version" << 3 << "members"
@@ -704,7 +710,8 @@ TEST_F(ReplCoordHBV1Test,
TEST_F(ReplCoordHBV1Test,
NodeChangesToRecoveringStateWhenAllNodesRespondToHeartbeatsWithUnauthorized) {
// Tests that a node that only has auth error heartbeats is recovering
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
assertStartSuccess(BSON("_id"
<< "mySet"
<< "version" << 1 << "members"
diff --git a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
index d4a6fbb276c..0e7fee0157f 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp
@@ -717,7 +717,8 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi
hbResp.addToBSON(&respObj2);
net->scheduleResponse(noi, net->now(), makeResponseStatus(respObj2.obj()));
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(1));
+ auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(1)};
startCapturingLogMessages();
// execute hb reconfig, which should fail with a log message; confirmed at end of test
net->runReadyNetworkOperations();
@@ -730,7 +731,6 @@ TEST_F(ReplCoordTest, NodeDoesNotAcceptHeartbeatReconfigWhileInTheMidstOfReconfi
"the midst of a configuration process"));
shutdown(opCtx.get());
reconfigThread.join();
- setMinimumLoggedSeverity(logv2::LogSeverity::Log());
}
TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary) {
@@ -774,9 +774,10 @@ TEST_F(ReplCoordTest, NodeAcceptsConfigFromAReconfigWithForceTrueWhileNotPrimary
class ReplCoordReconfigTest : public ReplCoordTest {
public:
- void setUp() {
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
- }
+ int counter = 0;
+ std::vector<HostAndPort> initialSyncNodes;
+ unittest::MinimumLoggedSeverityGuard severityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
BSONObj member(int id, std::string host) {
return BSON("_id" << id << "host" << host);
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index 57fcb8e5d7f..ab6b07c7cdd 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -6619,8 +6619,8 @@ TEST_F(ReplCoordTest,
TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
// Log all the election messages.
- setMinimumLoggedSeverity(logv2::LogComponent::kReplicationElection,
- logv2::LogSeverity::Debug(5));
+ auto replElectionAllSeverityGuard = unittest::MinimumLoggedSeverityGuard{
+ logv2::LogComponent::kReplicationElection, logv2::LogSeverity::Debug(5)};
startCapturingLogMessages();
// heartbeatTimeoutSecs is made large so we can advance the clock without worrying about
// additional heartbeats.
@@ -6679,8 +6679,8 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
ASSERT_EQ(1, countTextFormatLogLinesContaining("Rescheduling election timeout callback"));
ASSERT_EQ(1, countTextFormatLogLinesContaining("Canceling election timeout callback"));
- setMinimumLoggedSeverity(logv2::LogComponent::kReplicationElection,
- logv2::LogSeverity::Debug(4));
+ auto replElectionReducedSeverityGuard = unittest::MinimumLoggedSeverityGuard{
+ logv2::LogComponent::kReplicationElection, logv2::LogSeverity::Debug(4)};
net->enterNetwork();
until = electionTimeoutWhen + Milliseconds(500);
net->runUntil(until);
diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
index d13f8d80eb0..7d882e454cc 100644
--- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
+++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
@@ -87,7 +87,6 @@ ReplCoordTest::ReplCoordTest() {
}
ReplCoordTest::~ReplCoordTest() {
- clearMinimumLoggedSeverity(logv2::LogComponent::kReplicationElection);
globalFailPointRegistry().find("blockHeartbeatReconfigFinish")->setMode(FailPoint::off);
if (_callShutdown) {
diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp
index 4583e8232b6..862ba41e289 100644
--- a/src/mongo/db/repl/rollback_test_fixture.cpp
+++ b/src/mongo/db/repl/rollback_test_fixture.cpp
@@ -110,10 +110,6 @@ void RollbackTest::setUp() {
_replicationProcess->getConsistencyMarkers()->setMinValid(_opCtx.get(), OpTime{});
_replicationProcess->initializeRollbackID(_opCtx.get()).transitional_ignore();
- // Increase rollback log component verbosity for unit tests.
- setMinimumLoggedSeverity(logv2::LogComponent::kReplicationRollback,
- logv2::LogSeverity::Debug(2));
-
auto observerRegistry = checked_cast<OpObserverRegistry*>(serviceContext->getOpObserver());
observerRegistry->addObserver(std::make_unique<RollbackTestOpObserver>());
diff --git a/src/mongo/db/repl/rollback_test_fixture.h b/src/mongo/db/repl/rollback_test_fixture.h
index 79e27adc557..2ee64652aef 100644
--- a/src/mongo/db/repl/rollback_test_fixture.h
+++ b/src/mongo/db/repl/rollback_test_fixture.h
@@ -40,6 +40,10 @@
#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_d_test_fixture.h"
+#include "mongo/logv2/log_component.h"
+#include "mongo/logv2/log_severity.h"
+#include "mongo/unittest/log_test.h"
+#include "mongo/unittest/unittest.h"
namespace mongo {
namespace repl {
@@ -133,6 +137,10 @@ protected:
DropPendingCollectionReaper* _dropPendingCollectionReaper = nullptr;
ReadWriteConcernDefaultsLookupMock _lookupMock;
+
+ // Increase rollback log component verbosity for unit tests.
+ unittest::MinimumLoggedSeverityGuard severityGuard{logv2::LogComponent::kReplicationRollback,
+ logv2::LogSeverity::Debug(2)};
};
class RollbackTest::StorageInterfaceRollback : public StorageInterfaceImpl {
diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
index eb0f8d9f232..d59db60f743 100644
--- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
@@ -7175,16 +7175,9 @@ TEST_F(HeartbeatResponseTestTwoRetriesV1, HeartbeatThreeNonconsecutiveFailures)
class HeartbeatResponseHighVerbosityTestV1 : public HeartbeatResponseTestV1 {
public:
- virtual void setUp() {
- HeartbeatResponseTestV1::setUp();
- // set verbosity as high as the highest verbosity log message we'd like to check for
- setMinimumLoggedSeverity(logv2::LogSeverity::Debug(3));
- }
-
- virtual void tearDown() {
- HeartbeatResponseTestV1::tearDown();
- setMinimumLoggedSeverity(logv2::LogSeverity::Log());
- }
+ // set verbosity as high as the highest verbosity log message we'd like to check for
+ unittest::MinimumLoggedSeverityGuard severityGuard{logv2::LogComponent::kDefault,
+ logv2::LogSeverity::Debug(3)};
};
// TODO(dannenberg) figure out why this test is useful