-
Notifications
You must be signed in to change notification settings - Fork 345
Added enable flag for periodic task #901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
117fe92
a4d60b2
f28a517
d291617
3ea5357
0235bfc
1f679d2
d255a55
0ddcd62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,4 +418,39 @@ UTEST_F(PeriodicTaskLog, ErrorLog) { | |
task.Stop(); | ||
} | ||
|
||
UTEST(PeriodicTask, EnableDisable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test that checks the task does not keep running periodically if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test will also check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a lot to decipher in this test's logic - split it into some steps with empty lines and comment on each step There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test that checks that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test that checks that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test that after |
||
SimpleTaskData simple; | ||
|
||
constexpr auto period = 3ms; | ||
utils::PeriodicTask::Settings settings(period); | ||
|
||
constexpr Count n = 10; | ||
|
||
const auto start = std::chrono::steady_clock::now(); | ||
utils::PeriodicTask task("task", period, simple.GetTaskFunction()); | ||
EXPECT_TRUE(simple.WaitFor(period * n * kSlowRatio, [&simple]() { return simple.GetCount() > 5; })); | ||
auto countBeforeStop = simple.GetCount(); | ||
settings.enabled = false; | ||
task.SetSettings(settings); | ||
EXPECT_FALSE(simple.WaitFor(period * n * kSlowRatio, [&simple]() { return simple.GetCount() > 10; })); | ||
EXPECT_TRUE(countBeforeStop == simple.GetCount()); | ||
EXPECT_TRUE(task.IsRunning()); | ||
settings.enabled = true; | ||
task.SetSettings(settings); | ||
EXPECT_TRUE(simple.WaitFor(period * n * kSlowRatio, [&simple,countBeforeStop]() { return simple.GetCount() > 10; })); | ||
EXPECT_TRUE(task.IsRunning()); | ||
auto countBeforeStop2 = simple.GetCount(); | ||
settings.enabled = false; | ||
task.SetSettings(settings); | ||
EXPECT_FALSE(simple.WaitFor(period * n * kSlowRatio, [&simple]() { return simple.GetCount() > 20; })); | ||
EXPECT_TRUE(countBeforeStop2 == simple.GetCount()); | ||
EXPECT_TRUE(task.IsRunning()); | ||
|
||
task.ForceStepAsync(); | ||
EXPECT_TRUE(simple.WaitFor(period * n * kSlowRatio, [&simple]() { return simple.GetCount() > 30; })); | ||
|
||
task.Stop(); | ||
EXPECT_TRUE(!task.IsRunning()); | ||
} | ||
|
||
USERVER_NAMESPACE_END |
Uh oh!
There was an error while loading. Please reload this page.