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/raw_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/// cache-update-execution | If 'sequential' the caches are updated by testsuite sequentially in the order for cache component registration, which makes sense if service has components that push value into a cache component. If 'concurrent' the caches are updated concurrently with respect to the cache component dependencies. | concurrent
46///
47/// ## Static configuration example:
48///
49/// @snippet components/common_component_list_test.cpp Sample testsuite support component config
50
51// clang-format on
52
53class TestsuiteSupport final : public components::RawComponentBase {
54public:
55 /// @ingroup userver_component_names
56 /// @brief The default name of components::TestsuiteSupport
57 static constexpr std::string_view kName = "testsuite-support";
58
59 TestsuiteSupport(
60 const components::ComponentConfig& component_config,
61 const components::ComponentContext& component_context
62 );
63 ~TestsuiteSupport() override;
64
65 testsuite::CacheControl& GetCacheControl();
66 testsuite::DumpControl& GetDumpControl();
67 testsuite::PeriodicTaskControl& GetPeriodicTaskControl();
68 testsuite::TestpointControl& GetTestpointControl();
69 const testsuite::PostgresControl& GetPostgresControl();
70 const testsuite::RedisControl& GetRedisControl();
71 testsuite::TestsuiteTasks& GetTestsuiteTasks();
72 testsuite::HttpAllowedUrlsExtra& GetHttpAllowedUrlsExtra();
73 testsuite::GrpcControl& GetGrpcControl();
74 /// @returns 0 if timeout was not increased via
75 /// `testsuite-increased-timeout` static option,
76 /// `testsuite-increased-timeout` value otherwise
77 std::chrono::milliseconds GetIncreasedTimeout() const noexcept;
78
79 static yaml_config::Schema GetStaticConfigSchema();
80
81private:
82 void OnAllComponentsAreStopping() override;
83
84 const std::chrono::milliseconds increased_timeout_;
85 testsuite::CacheControl cache_control_;
86 testsuite::DumpControl dump_control_;
87 testsuite::PeriodicTaskControl periodic_task_control_;
88 testsuite::TestpointControl testpoint_control_;
89 testsuite::PostgresControl postgres_control_;
90 testsuite::RedisControl redis_control_;
91 std::unique_ptr<testsuite::TestsuiteTasks> testsuite_tasks_;
92 testsuite::HttpAllowedUrlsExtra http_allowed_urls_extra_;
93 testsuite::GrpcControl grpc_control_;
94};
95
96template <>
97inline constexpr bool kHasValidate<TestsuiteSupport> = true;
98
99} // namespace components
100
101USERVER_NAMESPACE_END