summaryrefslogtreecommitdiff
path: root/src/mongo/db/process_health/health_observer_test.cpp
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2022-03-11 15:23:57 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-11 15:54:23 +0000
commite146ca34cbec7301ba1be1cc3c10c56a53a107fc (patch)
treeb9240e07d0db7a42b5ce31f3216a34bd2327da32 /src/mongo/db/process_health/health_observer_test.cpp
parentea4409bb5186b84bff6651630aeb579f6d7f8588 (diff)
downloadmongo-e146ca34cbec7301ba1be1cc3c10c56a53a107fc.tar.gz
SERVER-64182 avoid duplicate health checks; cleanups
Diffstat (limited to 'src/mongo/db/process_health/health_observer_test.cpp')
-rw-r--r--src/mongo/db/process_health/health_observer_test.cpp29
1 files changed, 29 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 3cfe1dbe608..f10d2683967 100644
--- a/src/mongo/db/process_health/health_observer_test.cpp
+++ b/src/mongo/db/process_health/health_observer_test.cpp
@@ -221,6 +221,35 @@ TEST_F(FaultManagerTest,
resetManager(); // Before fields above go out of scope.
}
+TEST_F(FaultManagerTest, SchedulingDuplicateHealthChecksRejected) {
+ static constexpr int kLoops = 1000;
+ resetManager(std::make_unique<FaultManagerConfig>());
+ registerMockHealthObserver(FaultFacetType::kMock1, [] { return Severity::kOk; });
+ auto initialHealthCheckFuture = manager().startPeriodicHealthChecks();
+ waitForTransitionIntoState(FaultState::kOk);
+
+ auto observer = manager().getHealthObserversTest()[0];
+ auto initialStats = observer->getStats();
+
+ for (int i = 0; i < kLoops; ++i) {
+ // A check will not be scheduled if another check is running.
+ // Default interval is 1 sec so only 1/500 of checks will be scheduled.
+ scheduleNextImmediateCheck<HealthObserverMock>(FaultFacetType::kMock1);
+ sleepFor(Milliseconds(2));
+ }
+
+ // Sleep time here is not introducing flakiness - it only shows that even after
+ // waiting the total count of completed tests is lower than the total we scheduled.
+ sleepFor(Milliseconds(100));
+ auto finalStats = observer->getStats();
+
+ const auto totalCompletedCount =
+ finalStats.completedChecksCount - initialStats.completedChecksCount;
+ ASSERT_LT(totalCompletedCount, kLoops);
+ ASSERT_GT(totalCompletedCount, 0);
+ LOGV2(6418205, "Total completed checks count", "count"_attr = totalCompletedCount);
+}
+
} // namespace
} // namespace process_health
} // namespace mongo