diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/process_health/health_observer_test.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/process_health/health_observer_test.cpp')
| -rw-r--r-- | src/mongo/db/process_health/health_observer_test.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mongo/db/process_health/health_observer_test.cpp b/src/mongo/db/process_health/health_observer_test.cpp index f10d2683967..a2187f83e52 100644 --- a/src/mongo/db/process_health/health_observer_test.cpp +++ b/src/mongo/db/process_health/health_observer_test.cpp @@ -42,6 +42,7 @@ namespace process_health { // Using the common fault manager test suite. using test::FaultManagerTest; +using PeriodicHealthCheckContext = HealthObserverBase::PeriodicHealthCheckContext; namespace { // Tests that the mock observer is registered properly. @@ -250,6 +251,49 @@ TEST_F(FaultManagerTest, SchedulingDuplicateHealthChecksRejected) { LOGV2(6418205, "Total completed checks count", "count"_attr = totalCompletedCount); } +TEST_F(FaultManagerTest, HealthCheckThrowingExceptionMakesFailedStatus) { + resetManager(std::make_unique<FaultManagerConfig>()); + + FaultFacetType facetType = FaultFacetType::kMock1; + AtomicWord<bool> shouldThrow{false}; + + std::string logMsg = "Failed due to exception"; + + auto periodicCheckImpl = + [facetType, &shouldThrow, logMsg]( + PeriodicHealthCheckContext&& periodicHealthCheckCtx) -> Future<HealthCheckStatus> { + if (shouldThrow.load()) { + uasserted(ErrorCodes::InternalError, logMsg); + } + auto completionPf = makePromiseFuture<HealthCheckStatus>(); + completionPf.promise.emplaceValue(HealthCheckStatus(facetType, Severity::kOk, "success")); + return std::move(completionPf.future); + }; + + HealthObserverRegistration::registerObserverFactory( + [facetType, periodicCheckImpl](ServiceContext* svcCtx) { + return std::make_unique<HealthObserverMock>( + facetType, svcCtx, periodicCheckImpl, Milliseconds(Seconds(30))); + }); + + assertSoon([this] { return (manager().getFaultState() == FaultState::kStartupCheck); }); + + auto initialHealthCheckFuture = manager().startPeriodicHealthChecks(); + assertSoon([this] { return (manager().getFaultState() == FaultState::kOk); }); + + auto observer = manager().getHealthObserversTest().front(); + ASSERT_EQ(observer->getStats().completedChecksWithFaultCount, 0); + + shouldThrow.store(true); + assertSoon([this] { return (manager().getFaultState() == FaultState::kTransientFault); }); + + ASSERT_EQ(manager().currentFault()->toBSON()["facets"]["mock1"]["description"].String(), + "InternalError: Failed due to exception "); + + ASSERT_GTE(observer->getStats().completedChecksWithFaultCount, 1); + resetManager(); +} + } // namespace } // namespace process_health } // namespace mongo |
