Skip to content

Commit

Permalink
Add a setPerTryIdleTimeoutSeconds method to EngineBuilder. (#2601)
Browse files Browse the repository at this point in the history
Add a setPerTryIdleTimeoutSeconds method to EngineBuilder.
Add tests for setPerTryIdleTimeoutSeconds and setStreamIdleTimeoutSeconds.
Minor cleanup of envoy_config_test.cc.

Part of #2498

Risk Level: Low
Testing: Added unit tests
Docs Changes: N/A
Release Notes: Updated version_history.txt

Signed-off-by: Ryan Hamilton <rch@google.com>
  • Loading branch information
RyanTheOptimist authored Oct 11, 2022
1 parent 7222e45 commit 394e7f1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Bugfixes:

Features:

- api: Add a ``setPerTryIdleTimeoutSeconds()`` method to C++ EngineBuilder.
- kotlin: add a way to tell Envoy Mobile to respect system proxy settings by calling an ``enableProxying(true)`` method on the engine builder. (:issue:`#2416 <2416>`)


Expand Down
5 changes: 5 additions & 0 deletions library/cc/engine_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ EngineBuilder& EngineBuilder::setStreamIdleTimeoutSeconds(int stream_idle_timeou
return *this;
}

EngineBuilder& EngineBuilder::setPerTryIdleTimeoutSeconds(int per_try_idle_timeout_seconds) {
this->per_try_idle_timeout_seconds_ = per_try_idle_timeout_seconds;
return *this;
}

EngineBuilder& EngineBuilder::enableGzip(bool gzip_on) {
this->gzip_filter_ = gzip_on;
return *this;
Expand Down
1 change: 1 addition & 0 deletions library/cc/engine_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class EngineBuilder {
EngineBuilder& setAppId(const std::string& app_id);
EngineBuilder& setDeviceOs(const std::string& app_id);
EngineBuilder& setStreamIdleTimeoutSeconds(int stream_idle_timeout_seconds);
EngineBuilder& setPerTryIdleTimeoutSeconds(int per_try_idle_timeout_seconds);
EngineBuilder& enableGzip(bool gzip_on);
EngineBuilder& enableBrotli(bool brotli_on);
EngineBuilder& enableSocketTagging(bool socket_tagging_on);
Expand Down
54 changes: 41 additions & 13 deletions test/cc/unit/envoy_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {
using namespace Platform;

TEST(TestConfig, ConfigIsApplied) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;
engine_builder.addGrpcStatsDomain("asdf.fake.website")
.addConnectTimeoutSeconds(123)
.addDnsRefreshSeconds(456)
Expand All @@ -38,7 +38,7 @@ TEST(TestConfig, ConfigIsApplied) {
.setAppVersion("1.2.3")
.setAppId("1234-1234-1234")
.setDeviceOs("probably-ubuntu-on-CI");
auto config_str = engine_builder.generateConfigStr();
std::string config_str = engine_builder.generateConfigStr();

std::vector<std::string> must_contain = {
"- &stats_domain asdf.fake.website",
Expand All @@ -61,8 +61,8 @@ TEST(TestConfig, ConfigIsApplied) {
}

TEST(TestConfig, ConfigIsValid) {
auto engine_builder = EngineBuilder();
auto config_str = engine_builder.generateConfigStr();
EngineBuilder engine_builder;
std::string config_str = engine_builder.generateConfigStr();
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(absl::StrCat(config_header, config_str), bootstrap);

Expand All @@ -78,9 +78,9 @@ TEST(TestConfig, ConfigIsValid) {

#if !defined(__APPLE__)
TEST(TestConfig, SetUseDnsCAresResolver) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;
engine_builder.useDnsSystemResolver(false);
auto config_str = engine_builder.generateConfigStr();
std::string config_str = engine_builder.generateConfigStr();
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(absl::StrCat(config_header, config_str), bootstrap);

Expand All @@ -90,10 +90,10 @@ TEST(TestConfig, SetUseDnsCAresResolver) {
#endif

TEST(TestConfig, SetGzip) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;

engine_builder.enableGzip(false);
auto config_str = engine_builder.generateConfigStr();
std::string config_str = engine_builder.generateConfigStr();
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(absl::StrCat(config_header, config_str), bootstrap);
ASSERT_THAT(bootstrap.DebugString(), Not(HasSubstr("envoy.filters.http.decompressor")));
Expand All @@ -105,10 +105,10 @@ TEST(TestConfig, SetGzip) {
}

TEST(TestConfig, SetBrotli) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;

engine_builder.enableBrotli(false);
auto config_str = engine_builder.generateConfigStr();
std::string config_str = engine_builder.generateConfigStr();
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(absl::StrCat(config_header, config_str), bootstrap);
ASSERT_THAT(bootstrap.DebugString(), Not(HasSubstr("brotli.decompressor.v3.Brotli")));
Expand All @@ -120,10 +120,10 @@ TEST(TestConfig, SetBrotli) {
}

TEST(TestConfig, SetSocketTag) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;

engine_builder.enableSocketTagging(false);
auto config_str = engine_builder.generateConfigStr();
std::string config_str = engine_builder.generateConfigStr();
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(absl::StrCat(config_header, config_str), bootstrap);
ASSERT_THAT(bootstrap.DebugString(), Not(HasSubstr("http.socket_tag.SocketTag")));
Expand All @@ -135,7 +135,7 @@ TEST(TestConfig, SetSocketTag) {
}

TEST(TestConfig, SetAltSvcCache) {
auto engine_builder = EngineBuilder();
EngineBuilder engine_builder;

std::string config_str = absl::StrCat(config_header, engine_builder.generateConfigStr());

Expand All @@ -146,6 +146,34 @@ TEST(TestConfig, SetAltSvcCache) {
TestUtility::loadFromYaml(config_str, bootstrap);
}

TEST(TestConfig, StreamIdleTimeout) {
EngineBuilder engine_builder;

std::string config_str = absl::StrCat(config_header, engine_builder.generateConfigStr());
ASSERT_THAT(config_str, HasSubstr("&stream_idle_timeout 15s"));
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(config_str, bootstrap);

engine_builder.setStreamIdleTimeoutSeconds(42);
config_str = absl::StrCat(config_header, engine_builder.generateConfigStr());
ASSERT_THAT(config_str, HasSubstr("&stream_idle_timeout 42s"));
TestUtility::loadFromYaml(config_str, bootstrap);
}

TEST(TestConfig, PerTryIdleTimeout) {
EngineBuilder engine_builder;

std::string config_str = absl::StrCat(config_header, engine_builder.generateConfigStr());
ASSERT_THAT(config_str, HasSubstr("&per_try_idle_timeout 15s"));
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(config_str, bootstrap);

engine_builder.setPerTryIdleTimeoutSeconds(42);
config_str = absl::StrCat(config_header, engine_builder.generateConfigStr());
ASSERT_THAT(config_str, HasSubstr("&per_try_idle_timeout 42s"));
TestUtility::loadFromYaml(config_str, bootstrap);
}

TEST(TestConfig, RemainingTemplatesThrows) {
auto engine_builder = EngineBuilder("{{ template_that_i_will_not_fill }}");
try {
Expand Down

0 comments on commit 394e7f1

Please sign in to comment.