summaryrefslogtreecommitdiff
path: root/src/mongo/db/process_health/health_observer_test.cpp
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-08-25 21:07:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-25 21:32:24 +0000
commit5343c3e67bbe18b5eb3c7e2c1c891be58ba06157 (patch)
tree8b8bfee8cd4bafeca7ee583513a8784cec9562a4 /src/mongo/db/process_health/health_observer_test.cpp
parentd4b58bf7295da603ab7fda0d2ad4fc79f5d60bed (diff)
downloadmongo-5343c3e67bbe18b5eb3c7e2c1c891be58ba06157.tar.gz
SERVER-59567 Make the HealthManager to instantiate HealthObservers
Diffstat (limited to 'src/mongo/db/process_health/health_observer_test.cpp')
-rw-r--r--src/mongo/db/process_health/health_observer_test.cpp39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/mongo/db/process_health/health_observer_test.cpp b/src/mongo/db/process_health/health_observer_test.cpp
index 6c7e97763b8..6e1ab126004 100644
--- a/src/mongo/db/process_health/health_observer_test.cpp
+++ b/src/mongo/db/process_health/health_observer_test.cpp
@@ -29,6 +29,7 @@
#include "mongo/db/process_health/health_observer.h"
+#include "mongo/db/process_health/fault_manager_test_suite.h"
#include "mongo/db/process_health/health_observer_mock.h"
#include "mongo/db/process_health/health_observer_registration.h"
#include "mongo/db/service_context.h"
@@ -38,35 +39,27 @@ namespace mongo {
namespace process_health {
-namespace {
-
-class HealthObserverTest : public unittest::Test {
-public:
- void setUp() override {
- _svcCtx = ServiceContext::make();
- }
-
- void registerMock() {
- HealthObserverRegistration* reg = HealthObserverRegistration::get(_svcCtx.get());
- reg->registerObserverFactory(
- [](ServiceContext* svcCtx) { return std::make_unique<HealthObserverMock>(svcCtx); });
- }
-
- HealthObserverRegistration* registration() {
- return HealthObserverRegistration::get(_svcCtx.get());
- }
+// Using the common fault manager test suite.
+using test::FaultManagerTest;
-private:
- ServiceContext::UniqueServiceContext _svcCtx;
-};
+namespace {
-TEST_F(HealthObserverTest, Registration) {
- registerMock();
- auto allObservers = registration()->instantiateAllObservers();
+TEST_F(FaultManagerTest, Registration) {
+ registerMockHealthObserver([] { return 0; });
+ auto allObservers = healthObserverRegistration().instantiateAllObservers();
ASSERT_EQ(1, allObservers.size());
ASSERT_EQ(FaultFacetType::kMock, allObservers[0]->getType());
}
+TEST_F(FaultManagerTest, HealthCheckCreatesObservers) {
+ registerMockHealthObserver([] { return 0.1; });
+ ASSERT_EQ(0, manager().getHealthObserversTest().size());
+
+ // Trigger periodic health check.
+ manager().healthCheckTest();
+ ASSERT_EQ(1, manager().getHealthObserversTest().size());
+}
+
} // namespace
} // namespace process_health
} // namespace mongo