Skip to content

Commit

Permalink
Migrate to SimulatedTimeSystem in router tests (#6067)
Browse files Browse the repository at this point in the history
This partially addresses #4160

Signed-off-by: Michael Puncel mpuncel@squareup.com

Description: Migrate to simulated time instead of real time in router tests
Risk Level: low
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Partially Fixes #4160
  • Loading branch information
mpuncel authored and dnoe committed Feb 27, 2019
1 parent e8ecf08 commit 85408ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ envoy_cc_test(
"//test/mocks/ssl:ssl_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:environment_lib",
"//test/test_common:test_time_lib",
"//test/test_common:simulated_time_system_lib",
"//test/test_common:utility_lib",
],
)
Expand Down
9 changes: 5 additions & 4 deletions test/common/router/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "test/mocks/upstream/mocks.h"
#include "test/test_common/environment.h"
#include "test/test_common/printers.h"
#include "test/test_common/test_time.h"
#include "test/test_common/simulated_time_system.h"
#include "test/test_common/utility.h"

#include "gmock/gmock.h"
Expand Down Expand Up @@ -90,6 +90,9 @@ class RouterTestBase : public testing::Test {
router_.downstream_connection_.local_address_ = host_address_;
router_.downstream_connection_.remote_address_ =
Network::Utility::parseInternetAddressAndPort("1.2.3.4:80");

// Make the "system time" non-zero, because 0 is considered invalid by DateUtil.
test_time_.setMonotonicTime(std::chrono::milliseconds(50));
}

void expectResponseTimerCreate() {
Expand Down Expand Up @@ -206,7 +209,7 @@ class RouterTestBase : public testing::Test {
ON_CALL(callbacks_, connection()).WillByDefault(Return(&connection_));
}

DangerousDeprecatedTestTime test_time_;
Event::SimulatedTimeSystem test_time_;
std::string upstream_zone_{"to_az"};
envoy::api::v2::core::Locality upstream_locality_;
Stats::IsolatedStoreImpl stats_store_;
Expand Down Expand Up @@ -755,8 +758,6 @@ TEST_F(RouterTest, EnvoyUpstreamServiceTime) {

Http::HeaderMapPtr response_headers(new Http::TestHeaderMapImpl{{":status", "200"}});
EXPECT_CALL(cm_.conn_pool_.host_->outlier_detector_, putHttpResponseCode(200));
Http::TestHeaderMapImpl downstream_response_headers{{":status", "200"},
{"x-envoy-upstream-service-time", "0"}};
EXPECT_CALL(callbacks_, encodeHeaders_(_, true))
.WillOnce(Invoke([](Http::HeaderMap& headers, bool) {
EXPECT_NE(nullptr, headers.get(Http::Headers::get().EnvoyUpstreamServiceTime));
Expand Down

0 comments on commit 85408ad

Please sign in to comment.