userver: server::handlers::TestsControl Class Reference
Loading...
Searching...
No Matches
server::handlers::TestsControl Class Referencefinal

#include <userver/server/handlers/tests_control.hpp>

Detailed Description

Handler that allows to control the behavior of server from tests, and functional tests with testsuite in particular.

It is highly recommended to disable this handle in production via the load-enabled: false option.

The component must be configured in service config.

Static options:

Aside from common handler options component has the following options:

Name Description Default value
testpoint-url an URL that should be notified in the TESTPOINT_CALLBACK and TESTPOINT_CALLBACK_NONCORO macros -
skip-unregistered-testpoints do not send testpoints data for paths that were not registered by testpoint-url false
testpoint-timeout timeout to use while working with testpoint-url 1s

Static configuration example:

# yaml
tests-control:
skip-unregistered-testpoints: true
testpoint-timeout: 10s
testpoint-url: https://localhost:7891/testpoint
# Some options from server::handlers::HttpHandlerBase
path: /tests/{action}
method: POST
task_processor: main-task-processor

Scheme

Main user of the scheme is the pytest_userver.client.Client python class. In particular:

{
"action": "run_periodic_task" | "suspend_periodic_tasks" | "write_cache_dumps" | "read_cache_dumps" | "metrics_portability"
"testpoints": [<list of testpoints to register>]
"reset_metrics": true | false
"mock_now": <time in utils::datetime::Stringtime() acceptable format>
"invalidate_caches": <...>
"socket_logging_duplication": true | false
<...>
}
See also
Functional service tests (testsuite)
Examples
postgresql/functional_tests/basic_chaos/postgres_service.cpp, and samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp.

Definition at line 64 of file tests_control.hpp.

+ Inheritance diagram for server::handlers::TestsControl:
+ Collaboration diagram for server::handlers::TestsControl:

Public Member Functions

 TestsControl (const components::ComponentConfig &config, const components::ComponentContext &component_context)
 
formats::json::Value HandleRequestJsonThrow (const http::HttpRequest &request, const formats::json::Value &request_body, request::RequestContext &context) const override
 
- Public Member Functions inherited from server::handlers::HttpHandlerJsonBase
 HttpHandlerJsonBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
std::string HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const final
 
- Public Member Functions inherited from server::handlers::HttpHandlerBase
 HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
void HandleRequest (request::RequestBase &request, request::RequestContext &context) const override
 
void ReportMalformedRequest (request::RequestBase &request) const final
 
virtual const std::string & HandlerName () const
 
const std::vector< http::HttpMethod > & GetAllowedMethods () const
 
virtual logging::Level GetLogLevelForResponseStatus (http::HttpStatus status) const
 
std::string GetResponseDataForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const
 
void HandleCustomHandlerException (const http::HttpRequest &request, const CustomHandlerException &ex) const
 
void HandleUnknownException (const http::HttpRequest &request, const std::exception &ex) const
 
void LogUnknownException (const std::exception &ex) const
 Helper function to log an unknown exception.
 
const std::optional< logging::Level > & GetLogLevel () const
 Returns the default log level for the handler.
 
- Public Member Functions inherited from server::handlers::HandlerBase
 HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
bool IsMonitor () const
 Returns whether this is a monitoring handler.
 
const HandlerConfigGetConfig () const
 Returns handler config.
 
- Public Member Functions inherited from components::LoggableComponentBase
 LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
 
 LoggableComponentBase (LoggableComponentBase &&)=delete
 
 LoggableComponentBase (const LoggableComponentBase &)=delete
 
 ~LoggableComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HttpHandlerJsonBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HttpHandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr std::string_view kName = "tests-control"
 The default name of server::handlers::TestsControl.
 

Additional Inherited Members

- Protected Types inherited from server::handlers::HandlerBase
using HandlerErrorCode = handlers::HandlerErrorCode
 
using InternalMessage = handlers::InternalMessage
 
using ExternalBody = handlers::ExternalBody
 
using ClientError = handlers::ClientError
 
using InternalServerError = handlers::InternalServerError
 
- Protected Member Functions inherited from server::handlers::HttpHandlerJsonBase
void ParseRequestData (const http::HttpRequest &request, request::RequestContext &context) const override
 
- Protected Member Functions inherited from server::handlers::HttpHandlerBase
void ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const
 
virtual void OnRequestCompleteThrow (const http::HttpRequest &, request::RequestContext &) const
 
virtual void HandleStreamRequest (const server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const
 
virtual bool IsStreamed () const
 
virtual bool IsMethodStatisticIncluded () const
 
virtual bool NeedCheckAuth () const
 
virtual std::string GetRequestBodyForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &request_body) const
 Override it if you need a custom request body logging.
 
virtual std::string GetResponseDataForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const
 Override it if you need a custom response data logging.
 
virtual std::string GetMetaType (const http::HttpRequest &) const
 
- Static Protected Member Functions inherited from server::handlers::HttpHandlerJsonBase
static const formats::json::ValueGetRequestJson (const request::RequestContext &context)
 
static const formats::json::ValueGetResponseJson (const request::RequestContext &context)
 

Member Function Documentation

◆ HandleRequestJsonThrow()

formats::json::Value server::handlers::TestsControl::HandleRequestJsonThrow ( const http::HttpRequest & request,
const formats::json::Value & request_body,
request::RequestContext & context ) const
overridevirtual

The documentation for this class was generated from the following file: