userver: userver/testsuite/periodic_task_control.hpp Source File
Loading...
Searching...
No Matches
periodic_task_control.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/testsuite/periodic_task_control.hpp
4/// @brief @copybrief testsuite::PeriodicTaskControl
5
6#include <string>
7#include <unordered_map>
8#include <unordered_set>
9#include <vector>
10
11#include <userver/concurrent/variable.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace utils {
16class PeriodicTask;
17} // namespace utils
18
19namespace testsuite {
20
21/// @brief Periodic task control interface for testsuite
22/// @details All methods are coro-safe.
23class PeriodicTaskControl final {
24public:
25 bool RunPeriodicTask(const std::string& name);
26 void SuspendPeriodicTasks(const std::unordered_set<std::string>& names);
27
28private:
30
31 void RegisterPeriodicTask(const std::string& name, utils::PeriodicTask& task);
32
33 void UnregisterPeriodicTask(const std::string& name, utils::PeriodicTask& task);
34
35 utils::PeriodicTask& FindPeriodicTask(const std::string& name);
36
37 concurrent::Variable<std::unordered_map<std::string, utils::PeriodicTask&>> periodic_tasks_;
38};
39
40/// RAII helper for testsuite registration
42public:
43 PeriodicTaskRegistrationHolder(
44 PeriodicTaskControl& periodic_task_control,
45 std::string name,
46 utils::PeriodicTask& task
47 );
48 ~PeriodicTaskRegistrationHolder();
49
50 PeriodicTaskRegistrationHolder(const PeriodicTaskRegistrationHolder&) = delete;
51 PeriodicTaskRegistrationHolder(PeriodicTaskRegistrationHolder&&) = delete;
54
55private:
56 PeriodicTaskControl& periodic_task_control_;
57 std::string name_;
58 utils::PeriodicTask& task_;
59};
60
61} // namespace testsuite
62
63USERVER_NAMESPACE_END