userver: userver/testsuite/testsuite_support.hpp Source File
Loading...
Searching...
No Matches
testsuite_support.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/testsuite/testsuite_support.hpp
4/// @brief @copybrief components::TestsuiteSupport
5
6#include <userver/components/impl/component_base.hpp>
7#include <userver/testsuite/cache_control.hpp>
8#include <userver/testsuite/dump_control.hpp>
9#include <userver/testsuite/grpc_control.hpp>
10#include <userver/testsuite/http_allowed_urls_extra.hpp>
11#include <userver/testsuite/periodic_task_control.hpp>
12#include <userver/testsuite/postgres_control.hpp>
13#include <userver/testsuite/redis_control.hpp>
14#include <userver/testsuite/testpoint_control.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18/// Testsuite integration
19namespace testsuite {
20class TestsuiteTasks;
21}
22
23namespace components {
24
25// clang-format off
26
27/// @ingroup userver_components
28///
29/// @brief Testsuite support component
30///
31/// Provides additional functionality for testing, e.g. forced cache updates.
32///
33/// ## Static options:
34/// Name | Description | Default value
35/// ---- | ----------- | -------------
36/// testsuite-periodic-update-enabled | whether caches update periodically | true
37/// testsuite-pg-execute-timeout | execute timeout override for postgres | -
38/// testsuite-pg-statement-timeout | statement timeout override for postgres | -
39/// testsuite-pg-readonly-master-expected | mutes readonly master detection warning | false
40/// testsuite-redis-timeout-connect | minimum connection timeout for redis | -
41/// testsuite-redis-timeout-single | minimum single shard timeout for redis | -
42/// testsuite-redis-timeout-all | minimum command timeout for redis | -
43/// testsuite-tasks-enabled | enable testsuite tasks facility | false
44/// testsuite-increased-timeout | increase timeouts for connections, statement executions, RPC timeouts to avoid timeouts happening in testing environments, where the hardware differs from production. Overrides postgres, redis and grpc timeouts if these are missing | 0ms
45///
46/// ## Static configuration example:
47///
48/// @snippet components/common_component_list_test.cpp Sample testsuite support component config
49
50// clang-format on
51
52class TestsuiteSupport final : public components::impl::ComponentBase {
53 public:
54 /// @ingroup userver_component_names
55 /// @brief The default name of components::TestsuiteSupport
56 static constexpr std::string_view kName = "testsuite-support";
57
58 TestsuiteSupport(const components::ComponentConfig& component_config,
59 const components::ComponentContext& component_context);
60 ~TestsuiteSupport() override;
61
62 testsuite::CacheControl& GetCacheControl();
63 testsuite::DumpControl& GetDumpControl();
64 testsuite::PeriodicTaskControl& GetPeriodicTaskControl();
65 testsuite::TestpointControl& GetTestpointControl();
66 const testsuite::PostgresControl& GetPostgresControl();
67 const testsuite::RedisControl& GetRedisControl();
68 testsuite::TestsuiteTasks& GetTestsuiteTasks();
69 testsuite::HttpAllowedUrlsExtra& GetHttpAllowedUrlsExtra();
70 testsuite::GrpcControl& GetGrpcControl();
71 /// @returns 0 if timeout was not increased via
72 /// `testsuite-increased-timeout` static option,
73 /// `testsuite-increased-timeout` value otherwise
74 std::chrono::milliseconds GetIncreasedTimeout() const noexcept;
75
76 static yaml_config::Schema GetStaticConfigSchema();
77
78 private:
79 void OnAllComponentsAreStopping() override;
80
81 const std::chrono::milliseconds increased_timeout_;
82 testsuite::CacheControl cache_control_;
83 testsuite::DumpControl dump_control_;
84 testsuite::PeriodicTaskControl periodic_task_control_;
85 testsuite::TestpointControl testpoint_control_;
86 testsuite::PostgresControl postgres_control_;
87 testsuite::RedisControl redis_control_;
88 std::unique_ptr<testsuite::TestsuiteTasks> testsuite_tasks_;
89 testsuite::HttpAllowedUrlsExtra http_allowed_urls_extra_;
90 testsuite::GrpcControl grpc_control_;
91};
92
93template <>
94inline constexpr bool kHasValidate<TestsuiteSupport> = true;
95
96} // namespace components
97
98USERVER_NAMESPACE_END