mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmProcess: compute the timeout when needed
When a timeout is updated during runtime (e.g., via `TIMEOUT_AFTER_MATCH`), the actual timeout needs recomputed based on consideration of `StopTimeout` as well. Instead of using `Timeout` directly, add a `GetComputedTimeout` method which also retrieves the timeout reason based on which timeout is selected.
This commit is contained in:
@@ -813,9 +813,6 @@ bool cmCTestRunTest::ForkProcess()
|
||||
if (stop_time != std::chrono::system_clock::time_point()) {
|
||||
cmDuration timeUntilStop =
|
||||
(stop_time - std::chrono::system_clock::now()) % std::chrono::hours(24);
|
||||
if (timeUntilStop < timeRemaining) {
|
||||
timeRemaining = timeUntilStop;
|
||||
}
|
||||
this->TestProcess->SetStopTimeout(timeUntilStop);
|
||||
}
|
||||
|
||||
@@ -825,7 +822,16 @@ bool cmCTestRunTest::ForkProcess()
|
||||
}
|
||||
if (!timeout || timeRemaining < *timeout) {
|
||||
timeout = timeRemaining;
|
||||
this->TestProcess->SetTimeoutReason(cmProcess::TimeoutReason::StopTime);
|
||||
}
|
||||
|
||||
// Inform the test process of its normal timeout
|
||||
if (timeout) {
|
||||
this->TestProcess->SetTimeout(*timeout);
|
||||
}
|
||||
|
||||
// Ask the test process which timeout is in effect.
|
||||
if (auto ctimeout = this->TestProcess->GetComputedTimeout()) {
|
||||
timeout = ctimeout->Duration;
|
||||
}
|
||||
|
||||
if (timeout) {
|
||||
|
||||
@@ -158,9 +158,10 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity)
|
||||
|
||||
void cmProcess::StartTimer()
|
||||
{
|
||||
if (this->Timeout) {
|
||||
auto msec =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(*this->Timeout);
|
||||
if (auto ctimeout = this->GetComputedTimeout()) {
|
||||
this->TimeoutReason_ = ctimeout->Reason;
|
||||
auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
ctimeout->Duration);
|
||||
this->Timer.start(&cmProcess::OnTimeoutCB,
|
||||
static_cast<uint64_t>(msec.count()), 0,
|
||||
cm::uv_update_time::no);
|
||||
@@ -374,6 +375,24 @@ cmProcess::State cmProcess::GetProcessStatus()
|
||||
return this->ProcessState;
|
||||
}
|
||||
|
||||
cm::optional<cmProcess::ComputedTimeout> cmProcess::GetComputedTimeout() const
|
||||
{
|
||||
if (this->StopTimeout && this->Timeout) {
|
||||
if (*this->StopTimeout < *this->Timeout) {
|
||||
return ComputedTimeout{ TimeoutReason::StopTime, *this->StopTimeout };
|
||||
}
|
||||
return ComputedTimeout{ TimeoutReason::Normal, *this->Timeout };
|
||||
}
|
||||
if (this->StopTimeout) {
|
||||
return ComputedTimeout{ TimeoutReason::StopTime, *this->StopTimeout };
|
||||
}
|
||||
if (this->Timeout) {
|
||||
return ComputedTimeout{ TimeoutReason::Normal, *this->Timeout };
|
||||
}
|
||||
|
||||
return cm::nullopt;
|
||||
}
|
||||
|
||||
void cmProcess::ChangeTimeout(cmDuration t)
|
||||
{
|
||||
this->Timeout = t;
|
||||
|
||||
@@ -49,8 +49,13 @@ public:
|
||||
Normal,
|
||||
StopTime,
|
||||
};
|
||||
void SetTimeoutReason(TimeoutReason r) { this->TimeoutReason_ = r; }
|
||||
TimeoutReason GetTimeoutReason() const { return this->TimeoutReason_; }
|
||||
struct ComputedTimeout
|
||||
{
|
||||
TimeoutReason Reason;
|
||||
cmDuration Duration;
|
||||
};
|
||||
cm::optional<ComputedTimeout> GetComputedTimeout() const;
|
||||
|
||||
enum class State
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user