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/// 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::impl::ComponentBase {
54 public:
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(const components::ComponentConfig& component_config,
60 const components::ComponentContext& component_context);
61 ~TestsuiteSupport() override;
62
63 testsuite::CacheControl& GetCacheControl();
64 testsuite::DumpControl& GetDumpControl();
65 testsuite::PeriodicTaskControl& GetPeriodicTaskControl();
66 testsuite::TestpointControl& GetTestpointControl();
67 const testsuite::PostgresControl& GetPostgresControl();
68 const testsuite::RedisControl& GetRedisControl();
69 testsuite::TestsuiteTasks& GetTestsuiteTasks();
70 testsuite::HttpAllowedUrlsExtra& GetHttpAllowedUrlsExtra();
71 testsuite::GrpcControl& GetGrpcControl();
72 /// @returns 0 if timeout was not increased via
73 /// `testsuite-increased-timeout` static option,
74 /// `testsuite-increased-timeout` value otherwise
75 std::chrono::milliseconds GetIncreasedTimeout() const noexcept;
76
77 static yaml_config::Schema GetStaticConfigSchema();
78
79 private:
80 void OnAllComponentsAreStopping() override;
81
82 const std::chrono::milliseconds increased_timeout_;
83 testsuite::CacheControl cache_control_;
84 testsuite::DumpControl dump_control_;
85 testsuite::PeriodicTaskControl periodic_task_control_;
86 testsuite::TestpointControl testpoint_control_;
87 testsuite::PostgresControl postgres_control_;
88 testsuite::RedisControl redis_control_;
89 std::unique_ptr<testsuite::TestsuiteTasks> testsuite_tasks_;
90 testsuite::HttpAllowedUrlsExtra http_allowed_urls_extra_;
91 testsuite::GrpcControl grpc_control_;
92};
93
94template <>
95inline constexpr bool kHasValidate<TestsuiteSupport> = true;
96
97} // namespace components
98
99USERVER_NAMESPACE_END