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 of server::handlers::TestsControl :
| 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 |
Options inherited from server::handlers::HttpHandlerBase :
| Name | Description | Default value |
| log-level | Overrides log level for this handle. | <no override> |
| status-codes-log-level.* | HTTP status code -> log level map. Each of the elements: log level. | – |
| middlewares.pipeline-builder | Name of a component to build a middleware pipeline for this particular handler. | default-handler-middleware-pipeline-builder |
| middlewares.*.* | Per-middleware configuration. | – |
Options inherited from server::handlers::HandlerBase :
| Name | Description | Default value |
| path | If a request matches this path wildcard then process it by handler. | – |
| as_fallback | Set to "implicit-http-options" and do not specify a path if this handler processes the OPTIONS requests for paths that do not process OPTIONS method. Possible values: implicit-http-options, unknown. | – |
| task_processor | A task processor to execute the requests. | the 'default_task_processor' value from components::ManagerControllerComponent |
| method | Comma-separated list of allowed methods. | – |
| max_request_size | Maximum size of the whole request. Limits both the size of the request and the size of a decompressed request body (if compression is being used). Requests exceeding the limit are rejected with 'Request Entity Too Large' (413) HTTP code. | 1024 * 1024 |
| max_headers_size | Max request headers size of empty to do not limit. | 65536 |
| parse_args_from_body | Optional field to parse request according to x-www-form-urlencoded rules and make parameters accessible as query parameters. | false |
| auth.type | Auth type. | – |
| auth.types.[] | List of auth types. Each of the elements: auth type. | – |
| auth.* | Server::handlers::auth::HandlerAuthConfig authorization config. | – |
| url_trailing_slash | 'both' to treat URLs with and without a trailing slash as equal, 'strict-match' otherwise. Possible values: both, strict-match. | both |
| max_requests_in_flight | Integer to limit max pending requests to this handler. | <no limit> |
| request_body_size_log_limit | Trim the request to this size before logging. | 512 |
| request_headers_size_log_limit | Trim request headers to this size before logging. | 512 |
| response_data_size_log_limit | Trim responses to this size before logging. | 512 |
| max_requests_per_second | Integer to limit RPS to this handler. | <no limit> |
| decompress_request | Allow decompression of the requests. | true |
| throttling_enabled | Allow throttling of the requests by components::Server , for more info see its max_response_size_in_flight and requests_queue_size_threshold options. | true |
| set-response-server-hostname | Set to true to add the X-YaTaxi-Server-Hostname header with instance name, set to false to not add the header. | <takes the value from components::Server config> |
| response-body-stream | TODO. | false |
| monitor-handler | Overrides the in-code is_monitor flag that makes the handler run either on 'server.listener' or on 'server.listener-monitor'. | uses in-code flag value |
| set_tracing_headers | Whether to set http tracing headers (X-YaTraceId, X-YaSpanId, X-RequestId). | true |
| deadline_propagation_enabled | When set to false, disables deadline propagation within this handler. This includes: - reading the task-inherited deadline from HTTP headers and gRPC metadata; - interrupting operations when deadline expires; - propagating the deadline to downstream services and databases. Deadline propagation can also be disabled in the static config of: - components::Server (to set the default for all HTTP handlers). Deadline propagation is disabled if disabled statically OR dynamically. | true |
| deadline_expired_status_code | The HTTP status code to return if the request deadline expires. | taken from server.listener.handler-defaults.deadline_expired_status_code |
| enable_write_statistics | Whether to write handler statistics. | true |
Options inherited from components::ComponentBase :
| Name | Description | Default value |
| load-enabled | Set to false to disable loading of the component. | true |
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
"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/main.cpp.
Definition at line 65 of file tests_control.hpp.
|
|
| 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 |
| |
| std::string | HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const final |
| | Same as HandleRequest.
|
| |
| void | PrepareAndHandleRequest (http::HttpRequest &request, request::RequestContext &context) const override |
| |
| void | ReportMalformedRequest (http::HttpRequest &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 |
| |
|
std::string | GetUrlForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context) const |
| |
| void | HandleCustomHandlerException (const http::HttpRequest &request, request::RequestContext &context, const CustomHandlerException &ex) const |
| |
| void | HandleUnknownException (const http::HttpRequest &request, request::RequestContext &context, const std::exception &ex) const |
| |
|
void | LogUnknownException (const std::exception &ex, std::optional< logging::Level > log_level_override={}) const |
| | Helper function to log an unknown exception.
|
| |
|
const std::optional< logging::Level > & | GetLogLevel () const |
| | Returns the default log level for the handler.
|
| |
| bool | IsMonitor () const |
| | Returns whether this is a monitoring handler.
|
| |
|
const HandlerConfig & | GetConfig () const |
| | Returns handler config.
|
| |
| ComponentHealth | GetComponentHealth () const override |
| |
| void | OnLoadingCancelled () override |
| |
| void | OnAllComponentsLoaded () override |
| |
| void | OnAllComponentsAreStopping () override |
| |
|
| void | ParseRequestData (const http::HttpRequest &request, request::RequestContext &context) const override |
| |
|
void | ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const |
| |
| virtual std::string | HandleRequest (http::HttpRequest &request, request::RequestContext &context) const |
| |
| virtual void | HandleStreamRequest (server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const |
| |
| virtual bool | IsStreamed () const |
| |
| virtual bool | IsStreamed (const http::HttpRequest &, server::request::RequestContext &) 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 | GetUrlForLogging (const http::HttpRequest &request, request::RequestContext &context) const |
| | Override it if you need a custom request url logging.
|
| |
|
virtual std::string | GetMetaType (const http::HttpRequest &) const |
| |