userver: userver/server/handlers/tests_control.hpp Source File
Loading...
Searching...
No Matches
tests_control.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/tests_control.hpp
4/// @brief @copybrief server::handlers::TestsControl
5
6#include <memory>
7
8#include <userver/server/handlers/http_handler_json_base.hpp>
9#include <userver/testsuite/http_testpoint_client.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace testsuite::impl::actions {
14class BaseTestsuiteAction;
15}
16
17namespace server::handlers {
18
19// clang-format off
20
21/// @ingroup userver_components userver_http_handlers
22///
23/// @brief Handler that allows to control the behavior of server from tests,
24/// and @ref scripts/docs/en/userver/functional_testing.md "functional tests with testsuite" in particular.
25///
26/// It is highly recommended to disable this handle in production via the
27/// @ref userver_components "load-enabled: false" option.
28///
29/// The component must be configured in service config.
30///
31/// ## Static options of server::handlers::TestsControl :
32/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/tests_control.md
33///
34/// Options inherited from @ref server::handlers::HttpHandlerBase :
35/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/http_handler_base.md
36///
37/// Options inherited from @ref server::handlers::HandlerBase :
38/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/handler_base.md
39///
40/// Options inherited from @ref components::ComponentBase :
41/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
42///
43/// ## Static configuration example:
44///
45/// @snippet components/common_server_component_list_test.cpp Sample tests control component config
46///
47/// ## Scheme
48/// Main user of the scheme is the pytest_userver.client.Client python class.
49/// In particular:
50/// @code
51/// {
52/// "action": "run_periodic_task" | "suspend_periodic_tasks" | "write_cache_dumps" | "read_cache_dumps" | "metrics_portability"
53/// "testpoints": [<list of testpoints to register>]
54/// "reset_metrics": true | false
55/// "mock_now": <time in utils::datetime::Stringtime() acceptable format>
56/// "invalidate_caches": <...>
57/// "socket_logging_duplication": true | false
58/// <...>
59/// }
60/// @endcode
61///
62/// @see @ref scripts/docs/en/userver/functional_testing.md
63
64// clang-format on
65class TestsControl final : public HttpHandlerJsonBase {
66public:
67 TestsControl(const components::ComponentConfig& config, const components::ComponentContext& component_context);
68 ~TestsControl() override;
69
70 /// @ingroup userver_component_names
71 /// @brief The default name of server::handlers::TestsControl
72 static constexpr std::string_view kName = "tests-control";
73
74 formats::json::Value HandleRequestJsonThrow(
75 const http::HttpRequest& request,
76 const formats::json::Value& request_body,
77 request::RequestContext& context
78 ) const override;
79
80 static yaml_config::Schema GetStaticConfigSchema();
81
82private:
83 formats::json::Value PerformAction(const std::string& action_name, const formats::json::Value& request_body) const;
84
85 std::unique_ptr<testsuite::TestpointClientBase> testpoint_client_;
86 std::unordered_map<std::string, std::unique_ptr<testsuite::impl::actions::BaseTestsuiteAction>> actions_;
87};
88
89} // namespace server::handlers
90
91USERVER_NAMESPACE_END