userver: userver/server/handlers/tests_control.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 {
65 public:
66 TestsControl(const components::ComponentConfig& config,
67 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) const override;
78
79 static yaml_config::Schema GetStaticConfigSchema();
80
81 private:
82 formats::json::Value PerformAction(
83 const std::string& action_name,
84 const formats::json::Value& request_body) const;
85
86 std::unique_ptr<testsuite::TestpointClientBase> testpoint_client_;
87 std::unordered_map<
88 std::string,
89 std::unique_ptr<testsuite::impl::actions::BaseTestsuiteAction>>
90 actions_;
91};
92
93} // namespace server::handlers
94
95USERVER_NAMESPACE_END