summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapachee <[email protected]>2024-10-22 18:08:47 +0300
committerapachee <[email protected]>2024-10-22 19:06:38 +0300
commit0bd28574f1df329ac2b07bf9081184f739bcb483 (patch)
tree91ec9fa59e05ad2d29fd7da3c11b1383340ed833
parent3e48b93400ba91d4abcdf89e16aa8d2f1ff4e8c6 (diff)
[queues] YT-22794: Minor refactoring and more diagnostics for easier debugging
commit_hash:5eb01bc47cb7c5e868a4e59ea7f3794ea875c2d7
-rw-r--r--yt/yt/core/concurrency/scheduled_executor.cpp4
-rw-r--r--yt/yt/core/concurrency/unittests/scheduled_executor_ut.cpp45
2 files changed, 47 insertions, 2 deletions
diff --git a/yt/yt/core/concurrency/scheduled_executor.cpp b/yt/yt/core/concurrency/scheduled_executor.cpp
index 07ceb5069b8..f906e5545d1 100644
--- a/yt/yt/core/concurrency/scheduled_executor.cpp
+++ b/yt/yt/core/concurrency/scheduled_executor.cpp
@@ -38,9 +38,9 @@ bool TScheduledInvocationTimePolicy::IsEnabled()
return static_cast<bool>(Interval_);
}
-bool TScheduledInvocationTimePolicy::ShouldKickstart(const TOptions&)
+bool TScheduledInvocationTimePolicy::ShouldKickstart(const TOptions& interval)
{
- return IsEnabled();
+ return static_cast<bool>(interval);
}
void TScheduledInvocationTimePolicy::SetOptions(TOptions interval)
diff --git a/yt/yt/core/concurrency/unittests/scheduled_executor_ut.cpp b/yt/yt/core/concurrency/unittests/scheduled_executor_ut.cpp
index b6af4f8a4da..2d7143297de 100644
--- a/yt/yt/core/concurrency/unittests/scheduled_executor_ut.cpp
+++ b/yt/yt/core/concurrency/unittests/scheduled_executor_ut.cpp
@@ -93,6 +93,51 @@ TEST_W(TScheduledExecutorTest, SimpleScheduleOutOfBand)
EXPECT_GT(TDuration::MilliSeconds(20), executionDuration);
}
+TEST_W(TScheduledExecutorTest, SetOptionsAfterStartWithNonEmptyInterval)
+{
+ std::atomic<int> count = {0};
+
+ auto callback = BIND([&] {
+ ++count;
+ });
+
+ auto actionQueue = New<TActionQueue>();
+ auto executor = New<TScheduledExecutor>(
+ actionQueue->GetInvoker(),
+ callback,
+ std::nullopt);
+
+ executor->Start();
+ executor->SetOptions(TDuration::MilliSeconds(200));
+
+ TDelayedExecutor::WaitForDuration(TDuration::MilliSeconds(300));
+ WaitFor(executor->Stop())
+ .ThrowOnError();
+ EXPECT_GE(count.load(), 1);
+ EXPECT_LE(count.load(), 3);
+}
+
+TEST_W(TScheduledExecutorTest, SetOptionsAfterStartWithEmptyInterval)
+{
+ std::atomic<int> count = {0};
+
+ auto callback = BIND([&] {
+ ++count;
+ });
+
+ auto actionQueue = New<TActionQueue>();
+ // Divide by 16 to prevent overflow.
+ auto executor = New<TScheduledExecutor>(
+ actionQueue->GetInvoker(),
+ callback,
+ TDuration::Max() / 16);
+
+ executor->Start();
+ executor->SetOptions(std::nullopt);
+
+ EXPECT_EQ(count.load(), 0);
+}
+
TEST_W(TScheduledExecutorTest, ParallelStop)
{
auto interval = TDuration::MilliSeconds(10);