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"
25/// in particular.
26///
27/// It is highly recommended to disable this handle in production via the
28/// @ref userver_components "load-enabled: false" option.
29///
30/// The component must be configured in service config.
31///
32/// ## Static options:
33/// Aside from @ref userver_http_handlers "common handler options" component
34/// has the following options:
35///
36/// Name | Description | Default value
37/// ---- | ----------- | -------------
38/// testpoint-url | an URL that should be notified in the TESTPOINT_CALLBACK and TESTPOINT_CALLBACK_NONCORO macros | -
39/// skip-unregistered-testpoints | do not send testpoints data for paths that were not registered by `testpoint-url` | false
40/// testpoint-timeout | timeout to use while working with testpoint-url | 1s
41///
42/// ## Static configuration example:
43///
44/// @snippet components/common_server_component_list_test.cpp Sample tests control component config
45///
46/// ## Scheme
47/// Main user of the scheme is the pytest_userver.client.Client python class.
48/// In particular:
49/// @code
50/// {
51/// "action": "run_periodic_task" | "suspend_periodic_tasks" | "write_cache_dumps" | "read_cache_dumps" | "metrics_portability"
52/// "testpoints": [<list of testpoints to register>]
53/// "reset_metrics": true | false
54/// "mock_now": <time in utils::datetime::Stringtime() acceptable format>
55/// "invalidate_caches": <...>
56/// "socket_logging_duplication": true | false
57/// <...>
58/// }
59/// @endcode
60///
61/// @see @ref scripts/docs/en/userver/functional_testing.md
62
63// clang-format on
64class TestsControl final : public HttpHandlerJsonBase {
65public:
66 TestsControl(const components::ComponentConfig& config, const components::ComponentContext& component_context);
67 ~TestsControl() override;
68
69 /// @ingroup userver_component_names
70 /// @brief The default name of server::handlers::TestsControl
71 static constexpr std::string_view kName = "tests-control";
72
73 formats::json::Value HandleRequestJsonThrow(
74 const http::HttpRequest& request,
75 const formats::json::Value& request_body,
76 request::RequestContext& context
77 ) const override;
78
79 static yaml_config::Schema GetStaticConfigSchema();
80
81private:
82 formats::json::Value PerformAction(const std::string& action_name, const formats::json::Value& request_body) const;
83
84 std::unique_ptr<testsuite::TestpointClientBase> testpoint_client_;
85 std::unordered_map<std::string, std::unique_ptr<testsuite::impl::actions::BaseTestsuiteAction>> actions_;
86};
87
88} // namespace server::handlers
89
90USERVER_NAMESPACE_END