checker: make result timer interval configurable for testing

This commit is contained in:
Yonas Habteab 2025-09-25 09:49:17 +02:00
parent 62a43a6d4a
commit 39c1d10583
2 changed files with 20 additions and 5 deletions

View File

@ -71,7 +71,7 @@ void CheckerComponent::Start(bool runtimeCreated)
m_Thread = std::thread([this]() { CheckThreadProc(); });
m_ResultTimer = Timer::Create();
m_ResultTimer->SetInterval(5);
m_ResultTimer->SetInterval(m_ResultTimerInterval);
m_ResultTimer->OnTimerExpired.connect([this](const Timer * const&) { ResultTimerHandler(); });
m_ResultTimer->Start();
}
@ -376,3 +376,18 @@ unsigned long CheckerComponent::GetPendingCheckables()
return m_PendingCheckables.size();
}
/**
* Sets the interval in seconds for the result timer.
*
* The result timer periodically logs the number of pending and idle checkables
* as well as the checks per second rate. The default interval is 5 seconds.
*
* Note, this method must be called before the component is started to have an effect on the timer.
*
* @param interval Interval in seconds for the result timer.
*/
void CheckerComponent::SetResultTimerInterval(double interval)
{
m_ResultTimerInterval = interval;
}

View File

@ -73,12 +73,16 @@ public:
unsigned long GetIdleCheckables();
unsigned long GetPendingCheckables();
void SetResultTimerInterval(double interval);
private:
std::mutex m_Mutex;
std::condition_variable m_CV;
bool m_Stopped{false};
std::thread m_Thread;
double m_ResultTimerInterval{5.0}; // Interval in seconds for the result timer.
CheckableSet m_IdleCheckables;
CheckableSet m_PendingCheckables;
@ -90,13 +94,9 @@ private:
void ExecuteCheckHelper(const Checkable::Ptr& checkable);
void AdjustCheckTimer();
void ObjectHandler(const ConfigObject::Ptr& object);
void NextCheckChangedHandler(const Checkable::Ptr& checkable, double nextCheck = -1);
void RescheduleCheckTimer();
static CheckableScheduleInfo GetCheckableScheduleInfo(const Checkable::Ptr& checkable);
};