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 {
24 public:
25 bool RunPeriodicTask(const std::string& name);
26 void SuspendPeriodicTasks(const std::unordered_set<std::string>& names);
27
28 private:
30
31 void RegisterPeriodicTask(const std::string& name, utils::PeriodicTask& task);
32
33 void UnregisterPeriodicTask(const std::string& name,
34 utils::PeriodicTask& task);
35
36 utils::PeriodicTask& FindPeriodicTask(const std::string& name);
37
38 concurrent::Variable<std::unordered_map<std::string, utils::PeriodicTask&>>
39 periodic_tasks_;
40};
41
42/// RAII helper for testsuite registration
44 public:
45 PeriodicTaskRegistrationHolder(PeriodicTaskControl& periodic_task_control,
46 std::string name, utils::PeriodicTask& task);
47 ~PeriodicTaskRegistrationHolder();
48
49 PeriodicTaskRegistrationHolder(const PeriodicTaskRegistrationHolder&) =
50 delete;
51 PeriodicTaskRegistrationHolder(PeriodicTaskRegistrationHolder&&) = delete;
53 const PeriodicTaskRegistrationHolder&) = delete;
55 delete;
56
57 private:
58 PeriodicTaskControl& periodic_task_control_;
59 std::string name_;
60 utils::PeriodicTask& task_;
61};
62
63} // namespace testsuite
64
65USERVER_NAMESPACE_END