Skip to content

Commit

Permalink
feat core: add testsuite-increased-timeout option to TestsuiteSupport…
Browse files Browse the repository at this point in the history
… config

add `testsuite-increased-timeout` option to TestsuiteSupport config
8db3a5f4aa2719aa01a1bab39c5a8f092aa32258
  • Loading branch information
ArkadyRudenko committed Feb 21, 2024
1 parent 99bdb67 commit 2dc373a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/include/userver/testsuite/testsuite_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace components {
/// testsuite-redis-timeout-single | minimum single shard timeout for redis | -
/// testsuite-redis-timeout-all | minimum command timeout for redis | -
/// testsuite-tasks-enabled | enable testsuite tasks facility | false
/// testsuite-increased-timeout | increase timeouts for connections, statement executions, RPC timeouts to avoid timeouts happening in testing environments, where the hardware differs from production. Overrides postgres, redis and grpc timeouts if these are missing | 0ms
///
/// ## Static configuration example:
///
Expand All @@ -67,12 +68,17 @@ class TestsuiteSupport final : public components::impl::ComponentBase {
testsuite::TestsuiteTasks& GetTestsuiteTasks();
testsuite::HttpAllowedUrlsExtra& GetHttpAllowedUrlsExtra();
testsuite::GrpcControl& GetGrpcControl();
/// @returns 0 if timeout was not increased via
/// `testsuite-increased-timeout` static option,
/// `testsuite-increased-timeout` value otherwise
std::chrono::milliseconds GetIncreasedTimeout() const noexcept;

static yaml_config::Schema GetStaticConfigSchema();

private:
void OnAllComponentsAreStopping() override;

const std::chrono::milliseconds increased_timeout_;
testsuite::CacheControl cache_control_;
testsuite::DumpControl dump_control_;
testsuite::PeriodicTaskControl periodic_task_control_;
Expand Down
1 change: 1 addition & 0 deletions core/src/components/common_component_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ constexpr std::string_view kStaticConfig = R"(
testsuite-redis-timeout-connect: 5s
testsuite-redis-timeout-single: 1s
testsuite-redis-timeout-all: 750ms
testsuite-increased-timeout: 40s
# /// [Sample testsuite support component config]
# /// [Sample http client component config]
# yaml
Expand Down
14 changes: 13 additions & 1 deletion core/src/testsuite/testsuite_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ testsuite::GrpcControl ParseGrpcControl(

TestsuiteSupport::TestsuiteSupport(const components::ComponentConfig& config,
const components::ComponentContext&)
: cache_control_(
: increased_timeout_(
config["testsuite-increased-timeout"].As<std::chrono::milliseconds>(
0)),
cache_control_(
ParsePeriodicUpdatesMode(config["testsuite-periodic-update-enabled"]
.As<std::optional<bool>>())),
dump_control_(ParseDumpControl(config)),
Expand Down Expand Up @@ -114,6 +117,11 @@ testsuite::GrpcControl& TestsuiteSupport::GetGrpcControl() {
return grpc_control_;
}

std::chrono::milliseconds TestsuiteSupport::GetIncreasedTimeout() const
noexcept {
return increased_timeout_;
}

yaml_config::Schema TestsuiteSupport::GetStaticConfigSchema() {
return yaml_config::MergeSchemas<impl::ComponentBase>(R"(
type: object
Expand Down Expand Up @@ -157,6 +165,10 @@ additionalProperties: false
type: boolean
description: Weather or not testsuite tasks are enabled
defaultDescription: false
testsuite-increased-timeout:
type: string
description: increase timeouts in testing environments. Overrides postgres, redis and grpc timeouts if these are missing
defaultDescription: 0ms
)");
}

Expand Down

0 comments on commit 2dc373a

Please sign in to comment.