Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ envoy_cc_test(
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/test_common:logging_lib",
"//test/test_common:simulated_time_system_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/api/v2:discovery_cc",
"@envoy_api//envoy/api/v2:eds_cc",
Expand Down
16 changes: 13 additions & 3 deletions test/common/config/grpc_mux_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/runtime/mocks.h"
#include "test/test_common/logging.h"
#include "test/test_common/simulated_time_system.h"
#include "test/test_common/utility.h"

#include "gmock/gmock.h"
Expand All @@ -36,7 +37,7 @@ namespace {
class GrpcMuxImplTest : public testing::Test {
public:
GrpcMuxImplTest() : async_client_(new Grpc::MockAsyncClient()) {
dispatcher_.setTimeSystem(mock_time_system_);
dispatcher_.setTimeSystem(time_system_);
}

void setup() {
Expand Down Expand Up @@ -76,7 +77,7 @@ class GrpcMuxImplTest : public testing::Test {
Grpc::MockAsyncStream async_stream_;
std::unique_ptr<GrpcMuxImpl> grpc_mux_;
NiceMock<MockGrpcMuxCallbacks> callbacks_;
NiceMock<MockTimeSystem> mock_time_system_;
Event::SimulatedTimeSystem time_system_;
NiceMock<LocalInfo::MockLocalInfo> local_info_;
Stats::IsolatedStoreImpl stats_;
};
Expand Down Expand Up @@ -310,8 +311,17 @@ TEST_F(GrpcMuxImplTest, WatchDemux) {
expectSendMessage(type_url, {}, "2");
}

// Exactly one test requires a mock time system to provoke behavior that cannot
// easily be achieved with a SimulatedTimeSystem.
class GrpcMuxImplTestWithMockTimeSystem : public GrpcMuxImplTest {
protected:
GrpcMuxImplTestWithMockTimeSystem() { dispatcher_.setTimeSystem(mock_time_system_); }

MockTimeSystem mock_time_system_;
};

// Verifies that warning messages get logged when Envoy detects too many requests.
TEST_F(GrpcMuxImplTest, TooManyRequests) {
TEST_F(GrpcMuxImplTestWithMockTimeSystem, TooManyRequests) {
setup();

EXPECT_CALL(async_stream_, sendMessage(_, false)).Times(AtLeast(100));
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ envoy_cc_fuzz_test(
"//test/mocks/ssl:ssl_mocks",
"//test/mocks/tracing:tracing_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:test_time_lib",
"//test/test_common:simulated_time_system_lib",
"@envoy_api//envoy/config/filter/network/http_connection_manager/v2:http_connection_manager_cc",
],
)
Expand Down
9 changes: 4 additions & 5 deletions test/common/http/conn_manager_impl_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "test/mocks/ssl/mocks.h"
#include "test/mocks/tracing/mocks.h"
#include "test/mocks/upstream/mocks.h"
#include "test/test_common/test_time.h"
#include "test/test_common/simulated_time_system.h"

#include "gmock/gmock.h"

Expand All @@ -56,7 +56,7 @@ class FuzzConfig : public ConnectionManagerConfig {
};

FuzzConfig()
: route_config_provider_(test_time_.timeSystem()),
: route_config_provider_(time_system_),
stats_{{ALL_HTTP_CONN_MAN_STATS(POOL_COUNTER(fake_stats_), POOL_GAUGE(fake_stats_),
POOL_HISTOGRAM(fake_stats_))},
"",
Expand Down Expand Up @@ -121,7 +121,7 @@ class FuzzConfig : public ConnectionManagerConfig {
MockStreamEncoderFilter* encoder_filter_{};
NiceMock<MockFilterChainFactory> filter_factory_;
absl::optional<std::chrono::milliseconds> idle_timeout_;
DangerousDeprecatedTestTime test_time_;
Event::SimulatedTimeSystem time_system_;
RouteConfigProvider route_config_provider_;
std::string server_name_;
Stats::IsolatedStoreImpl fake_stats_;
Expand Down Expand Up @@ -382,7 +382,6 @@ DEFINE_PROTO_FUZZER(const test::common::http::ConnManagerImplTestCase& input) {
NiceMock<LocalInfo::MockLocalInfo> local_info;
NiceMock<Upstream::MockClusterManager> cluster_manager;
NiceMock<Network::MockReadFilterCallbacks> filter_callbacks;
NiceMock<MockTimeSystem> time_system;
std::unique_ptr<Ssl::MockConnection> ssl_connection;
bool connection_alive = true;

Expand All @@ -396,7 +395,7 @@ DEFINE_PROTO_FUZZER(const test::common::http::ConnManagerImplTestCase& input) {
std::make_shared<Network::Address::Ipv4Instance>("0.0.0.0");

ConnectionManagerImpl conn_manager(config, drain_close, random, tracer, runtime, local_info,
cluster_manager, nullptr, time_system);
cluster_manager, nullptr, config.time_system_);
conn_manager.initializeReadFilterCallbacks(filter_callbacks);

std::vector<FuzzStreamPtr> streams;
Expand Down
2 changes: 1 addition & 1 deletion test/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ envoy_cc_test(
"//test/mocks/stats:stats_mocks",
"//test/test_common:environment_lib",
"//test/test_common:network_utility_lib",
"//test/test_common:test_time_lib",
"//test/test_common:simulated_time_system_lib",
],
)

Expand Down
10 changes: 5 additions & 5 deletions test/common/network/connection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "test/test_common/environment.h"
#include "test/test_common/network_utility.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 @@ -77,7 +77,7 @@ INSTANTIATE_TEST_CASE_P(IpVersions, ConnectionImplDeathTest,
TestUtility::ipTestParamsToString);

TEST_P(ConnectionImplDeathTest, BadFd) {
MockTimeSystem time_system;
Event::SimulatedTimeSystem time_system;
Event::DispatcherImpl dispatcher(time_system);
EXPECT_DEATH_LOG_TO_STDERR(
ConnectionImpl(dispatcher, std::make_unique<ConnectionSocketImpl>(-1, nullptr, nullptr),
Expand Down Expand Up @@ -169,7 +169,7 @@ class ConnectionImplTest : public testing::TestWithParam<Address::IpVersion> {
}

protected:
MockTimeSystem time_system_;
Event::SimulatedTimeSystem time_system_;
Event::DispatcherPtr dispatcher_;
Stats::IsolatedStoreImpl stats_store_;
Network::TcpListenSocket socket_{Network::Test::getAnyAddress(GetParam()), nullptr, true};
Expand Down Expand Up @@ -1271,7 +1271,7 @@ TEST_P(ReadBufferLimitTest, SomeLimit) {
class TcpClientConnectionImplTest : public testing::TestWithParam<Address::IpVersion> {
protected:
TcpClientConnectionImplTest() : dispatcher_(time_system_) {}
MockTimeSystem time_system_;
Event::SimulatedTimeSystem time_system_;
Event::DispatcherImpl dispatcher_;
};
INSTANTIATE_TEST_CASE_P(IpVersions, TcpClientConnectionImplTest,
Expand Down Expand Up @@ -1312,7 +1312,7 @@ TEST_P(TcpClientConnectionImplTest, BadConnectConnRefused) {
class PipeClientConnectionImplTest : public testing::Test {
protected:
PipeClientConnectionImplTest() : dispatcher_(time_system_) {}
MockTimeSystem time_system_;
Event::SimulatedTimeSystem time_system_;
Event::DispatcherImpl dispatcher_;
const std::string path_{TestEnvironment::unixDomainSocketPath("foo")};
};
Expand Down
1 change: 1 addition & 0 deletions test/common/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ envoy_cc_test(
"//test/mocks/grpc:grpc_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:simulated_time_system_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/api/v2:eds_cc",
"@envoy_api//envoy/api/v2/endpoint:endpoint_cc",
Expand Down
28 changes: 9 additions & 19 deletions test/common/upstream/load_stats_reporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "test/mocks/grpc/mocks.h"
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/upstream/mocks.h"
#include "test/test_common/simulated_time_system.h"
#include "test/test_common/utility.h"

#include "gmock/gmock.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ class LoadStatsReporterTest : public testing::Test {
Event::TimerCb response_timer_cb_;
Grpc::MockAsyncStream async_stream_;
Grpc::MockAsyncClient* async_client_;
MockTimeSystem time_system_;
Event::SimulatedTimeSystem time_system_;
NiceMock<LocalInfo::MockLocalInfo> local_info_;
};

Expand All @@ -93,14 +94,12 @@ TEST_F(LoadStatsReporterTest, TestPubSub) {
EXPECT_CALL(*async_client_, start(_, _)).WillOnce(Return(&async_stream_));
EXPECT_CALL(async_stream_, sendMessage(_, _));
createLoadStatsReporter();
EXPECT_CALL(time_system_, monotonicTime());
deliverLoadStatsResponse({"foo"});

EXPECT_CALL(async_stream_, sendMessage(_, _));
EXPECT_CALL(*response_timer_, enableTimer(std::chrono::milliseconds(42000)));
response_timer_cb_();

EXPECT_CALL(time_system_, monotonicTime());
deliverLoadStatsResponse({"bar"});

EXPECT_CALL(async_stream_, sendMessage(_, _));
Expand All @@ -114,8 +113,7 @@ TEST_F(LoadStatsReporterTest, ExistingClusters) {
// Initially, we have no clusters to report on.
expectSendMessage({});
createLoadStatsReporter();
EXPECT_CALL(time_system_, monotonicTime())
.WillOnce(Return(MonotonicTime(std::chrono::microseconds(3))));
time_system_.setMonotonicTime(std::chrono::microseconds(3));
// Start reporting on foo.
NiceMock<MockCluster> foo_cluster;
foo_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(2);
Expand All @@ -125,8 +123,7 @@ TEST_F(LoadStatsReporterTest, ExistingClusters) {
deliverLoadStatsResponse({"foo"});
// Initial stats report for foo on timer tick.
foo_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(5);
EXPECT_CALL(time_system_, monotonicTime())
.WillOnce(Return(MonotonicTime(std::chrono::microseconds(4))));
time_system_.setMonotonicTime(std::chrono::microseconds(4));
{
envoy::api::v2::endpoint::ClusterStats foo_cluster_stats;
foo_cluster_stats.set_cluster_name("foo");
Expand All @@ -143,15 +140,12 @@ TEST_F(LoadStatsReporterTest, ExistingClusters) {
bar_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);

// Start reporting on bar.
EXPECT_CALL(time_system_, monotonicTime())
.WillOnce(Return(MonotonicTime(std::chrono::microseconds(6))));
time_system_.setMonotonicTime(std::chrono::microseconds(6));
deliverLoadStatsResponse({"foo", "bar"});
// Stats report foo/bar on timer tick.
foo_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);
bar_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);
EXPECT_CALL(time_system_, monotonicTime())
.Times(2)
.WillRepeatedly(Return(MonotonicTime(std::chrono::microseconds(28))));
time_system_.setMonotonicTime(std::chrono::microseconds(28));
{
envoy::api::v2::endpoint::ClusterStats foo_cluster_stats;
foo_cluster_stats.set_cluster_name("foo");
Expand All @@ -177,8 +171,7 @@ TEST_F(LoadStatsReporterTest, ExistingClusters) {
// Stats report for bar on timer tick.
foo_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(5);
bar_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(5);
EXPECT_CALL(time_system_, monotonicTime())
.WillOnce(Return(MonotonicTime(std::chrono::microseconds(33))));
time_system_.setMonotonicTime(std::chrono::microseconds(33));
{
envoy::api::v2::endpoint::ClusterStats bar_cluster_stats;
bar_cluster_stats.set_cluster_name("bar");
Expand All @@ -195,15 +188,12 @@ TEST_F(LoadStatsReporterTest, ExistingClusters) {
bar_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);

// Start tracking foo again, we should forget earlier history for foo.
EXPECT_CALL(time_system_, monotonicTime())
.WillOnce(Return(MonotonicTime(std::chrono::microseconds(43))));
time_system_.setMonotonicTime(std::chrono::microseconds(43));
deliverLoadStatsResponse({"foo", "bar"});
// Stats report foo/bar on timer tick.
foo_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);
bar_cluster.info_->load_report_stats_.upstream_rq_dropped_.add(1);
EXPECT_CALL(time_system_, monotonicTime())
.Times(2)
.WillRepeatedly(Return(MonotonicTime(std::chrono::microseconds(47))));
time_system_.setMonotonicTime(std::chrono::microseconds(47));
{
envoy::api::v2::endpoint::ClusterStats foo_cluster_stats;
foo_cluster_stats.set_cluster_name("foo");
Expand Down
1 change: 1 addition & 0 deletions test/extensions/stats_sinks/metrics_service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ envoy_extension_cc_test(
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:simulated_time_system_lib",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/stats/mocks.h"
#include "test/mocks/thread_local/mocks.h"
#include "test/test_common/simulated_time_system.h"

using namespace std::chrono_literals;
using testing::_;
Expand Down Expand Up @@ -99,10 +100,10 @@ class MetricsServiceSinkTest : public testing::Test {};

TEST(MetricsServiceSinkTest, CheckSendCall) {
NiceMock<Stats::MockSource> source;
NiceMock<MockTimeSystem> mock_time;
Event::SimulatedTimeSystem time_system;
std::shared_ptr<MockGrpcMetricsStreamer> streamer_{new MockGrpcMetricsStreamer()};

MetricsServiceSink sink(streamer_, mock_time);
MetricsServiceSink sink(streamer_, time_system);

auto counter = std::make_shared<NiceMock<Stats::MockCounter>>();
counter->name_ = "test_counter";
Expand All @@ -127,10 +128,10 @@ TEST(MetricsServiceSinkTest, CheckSendCall) {

TEST(MetricsServiceSinkTest, CheckStatsCount) {
NiceMock<Stats::MockSource> source;
NiceMock<MockTimeSystem> mock_time;
Event::SimulatedTimeSystem time_system;
std::shared_ptr<TestGrpcMetricsStreamer> streamer_{new TestGrpcMetricsStreamer()};

MetricsServiceSink sink(streamer_, mock_time);
MetricsServiceSink sink(streamer_, time_system);

auto counter = std::make_shared<NiceMock<Stats::MockCounter>>();
counter->name_ = "test_counter";
Expand Down