diff --git a/test/common/grpc/grpc_client_integration_test_harness.h b/test/common/grpc/grpc_client_integration_test_harness.h index c2212e054ba4a..1405c4ab4c1ce 100644 --- a/test/common/grpc/grpc_client_integration_test_harness.h +++ b/test/common/grpc/grpc_client_integration_test_harness.h @@ -208,8 +208,8 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest { virtual void initialize() { if (fake_upstream_ == nullptr) { - fake_upstream_ = - std::make_unique(0, FakeHttpConnection::Type::HTTP2, ipVersion()); + fake_upstream_ = std::make_unique(0, FakeHttpConnection::Type::HTTP2, + ipVersion(), test_time_.timeSystem()); } switch (clientType()) { case ClientType::EnvoyGrpc: @@ -473,7 +473,8 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest { async_client_transport_socket_ = mock_cluster_info_->transport_socket_factory_->createTransportSocket(); fake_upstream_ = std::make_unique(createUpstreamSslContext(), 0, - FakeHttpConnection::Type::HTTP2, ipVersion()); + FakeHttpConnection::Type::HTTP2, ipVersion(), + test_time_.timeSystem()); GrpcClientIntegrationTest::initialize(); } diff --git a/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc b/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc index 7888dfc9a1554..95770f7899b01 100644 --- a/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc +++ b/test/extensions/access_loggers/http_grpc/grpc_access_log_integration_test.cc @@ -20,11 +20,13 @@ namespace { class AccessLogIntegrationTest : public HttpIntegrationTest, public Grpc::GrpcClientIntegrationParamTest { public: - AccessLogIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion()) {} + AccessLogIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion(), realTime()) {} void createUpstreams() override { HttpIntegrationTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } void initialize() override { diff --git a/test/extensions/filters/http/cors/cors_filter_integration_test.cc b/test/extensions/filters/http/cors/cors_filter_integration_test.cc index dac0c8600c019..ac16d4b19f036 100644 --- a/test/extensions/filters/http/cors/cors_filter_integration_test.cc +++ b/test/extensions/filters/http/cors/cors_filter_integration_test.cc @@ -9,7 +9,8 @@ namespace Envoy { class CorsFilterIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - CorsFilterIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + CorsFilterIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override { config_helper_.addFilter("name: envoy.cors"); diff --git a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc index 05868d0681b04..4af9c99935b49 100644 --- a/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc +++ b/test/extensions/filters/http/grpc_json_transcoder/grpc_json_transcoder_integration_test.cc @@ -24,7 +24,7 @@ class GrpcJsonTranscoderIntegrationTest public testing::TestWithParam { public: GrpcJsonTranscoderIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} /** * Global initializer for all integration tests. */ diff --git a/test/extensions/filters/http/gzip/BUILD b/test/extensions/filters/http/gzip/BUILD index 77e9d15e18d7c..762ec84637cc1 100644 --- a/test/extensions/filters/http/gzip/BUILD +++ b/test/extensions/filters/http/gzip/BUILD @@ -31,6 +31,7 @@ envoy_cc_test( "//source/common/decompressor:decompressor_lib", "//source/extensions/filters/http/gzip:config", "//test/integration:http_integration_lib", + "//test/test_common:simulated_time_system_lib", "//test/test_common:utility_lib", ], ) diff --git a/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc b/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc index e764552a59d9c..54db20736570c 100644 --- a/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc +++ b/test/extensions/filters/http/gzip/gzip_filter_integration_test.cc @@ -1,6 +1,9 @@ +#include "envoy/event/timer.h" + #include "common/decompressor/zlib_decompressor_impl.h" #include "test/integration/http_integration.h" +#include "test/test_common/simulated_time_system.h" #include "test/test_common/utility.h" #include "gtest/gtest.h" @@ -10,7 +13,8 @@ namespace Envoy { class GzipIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - GzipIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + GzipIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), simTime()) {} void SetUp() override { decompressor_.init(window_bits); } void TearDown() override { cleanupUpstreamAndDownstream(); } diff --git a/test/extensions/filters/http/jwt_authn/filter_integration_test.cc b/test/extensions/filters/http/jwt_authn/filter_integration_test.cc index c2e0a6cdc198c..19c91f6655f2e 100644 --- a/test/extensions/filters/http/jwt_authn/filter_integration_test.cc +++ b/test/extensions/filters/http/jwt_authn/filter_integration_test.cc @@ -134,7 +134,8 @@ class RemoteJwksIntegrationTest : public HttpProtocolIntegrationTest { void createUpstreams() override { HttpProtocolIntegrationTest::createUpstreams(); // for Jwks upstream. - fake_upstreams_.emplace_back(new FakeUpstream(0, GetParam().upstream_protocol, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, GetParam().upstream_protocol, version_, timeSystem())); } void initializeFilter() { diff --git a/test/extensions/filters/http/lua/lua_integration_test.cc b/test/extensions/filters/http/lua/lua_integration_test.cc index 3672df1edd413..d53cc36d93bfb 100644 --- a/test/extensions/filters/http/lua/lua_integration_test.cc +++ b/test/extensions/filters/http/lua/lua_integration_test.cc @@ -11,12 +11,15 @@ namespace { class LuaIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - LuaIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + LuaIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void createUpstreams() override { HttpIntegrationTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); } void initializeFilter(const std::string& filter_config) { diff --git a/test/extensions/filters/http/squash/squash_filter_integration_test.cc b/test/extensions/filters/http/squash/squash_filter_integration_test.cc index fd8379194900f..c89e4d7d6a48d 100644 --- a/test/extensions/filters/http/squash/squash_filter_integration_test.cc +++ b/test/extensions/filters/http/squash/squash_filter_integration_test.cc @@ -18,7 +18,8 @@ namespace Envoy { class SquashFilterIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - SquashFilterIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + SquashFilterIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} ~SquashFilterIntegrationTest() { if (fake_squash_connection_) { @@ -70,7 +71,8 @@ class SquashFilterIntegrationTest : public HttpIntegrationTest, void createUpstreams() override { HttpIntegrationTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); fake_upstreams_.back()->set_allow_unexpected_disconnects(true); } diff --git a/test/extensions/filters/network/rbac/integration_test.cc b/test/extensions/filters/network/rbac/integration_test.cc index 8edfc9c8d11d5..59a44801a2caf 100644 --- a/test/extensions/filters/network/rbac/integration_test.cc +++ b/test/extensions/filters/network/rbac/integration_test.cc @@ -19,7 +19,7 @@ class RoleBasedAccessControlNetworkFilterIntegrationTest public testing::TestWithParam { public: RoleBasedAccessControlNetworkFilterIntegrationTest() - : BaseIntegrationTest(GetParam(), rbac_config) {} + : BaseIntegrationTest(GetParam(), realTime(), rbac_config) {} static void SetUpTestCase() { rbac_config = ConfigHelper::BASE_CONFIG + R"EOF( diff --git a/test/extensions/filters/network/thrift_proxy/integration.h b/test/extensions/filters/network/thrift_proxy/integration.h index 75f421a8007bb..38c3e9850f067 100644 --- a/test/extensions/filters/network/thrift_proxy/integration.h +++ b/test/extensions/filters/network/thrift_proxy/integration.h @@ -50,7 +50,7 @@ struct PayloadOptions { class BaseThriftIntegrationTest : public BaseIntegrationTest { public: BaseThriftIntegrationTest() - : BaseIntegrationTest(Network::Address::IpVersion::v4, thrift_config_) {} + : BaseIntegrationTest(Network::Address::IpVersion::v4, realTime(), thrift_config_) {} /** * Given PayloadOptions, generate a client request and server response and store the diff --git a/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc b/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc index 0df09e6249ef4..55ac4cd324774 100644 --- a/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc +++ b/test/extensions/stats_sinks/metrics_service/metrics_service_integration_test.cc @@ -21,11 +21,12 @@ class MetricsServiceIntegrationTest : public HttpIntegrationTest, public Grpc::GrpcClientIntegrationParamTest { public: MetricsServiceIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion()) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion(), realTime()) {} void createUpstreams() override { HttpIntegrationTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); fake_upstreams_.back()->set_allow_unexpected_disconnects(true); } diff --git a/test/integration/BUILD b/test/integration/BUILD index e5fbe30f6bd45..97a8fbecb5dc4 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -217,6 +217,7 @@ envoy_cc_test_library( ":add_trailers_filter_config_lib", ":integration_lib", ":test_host_predicate_lib", + "//include/envoy/event:timer_interface", "//source/extensions/filters/http/router:config", "//source/extensions/filters/network/http_connection_manager:config", "//test/common/upstream:utility_lib", @@ -314,7 +315,9 @@ envoy_cc_test_library( "//test/test_common:environment_lib", "//test/test_common:network_utility_lib", "//test/test_common:printers_lib", + "//test/test_common:simulated_time_system_lib", "//test/test_common:test_time_lib", + "//test/test_common:test_time_system_interface", "//test/test_common:utility_lib", ], ) diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index 5a2f2f11e7734..79982c2af3c2e 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -65,7 +65,7 @@ class AdsIntegrationBaseTest : public HttpIntegrationTest { AdsIntegrationBaseTest(Http::CodecClient::Type downstream_protocol, Network::Address::IpVersion version, const std::string& config = ConfigHelper::HTTP_PROXY_CONFIG) - : HttpIntegrationTest(downstream_protocol, version, config) {} + : HttpIntegrationTest(downstream_protocol, version, realTime(), config) {} void createAdsConnection(FakeUpstream& upstream) { ads_upstream_ = &upstream; @@ -104,8 +104,8 @@ class AdsIntegrationTest : public AdsIntegrationBaseTest, void createUpstreams() override { AdsIntegrationBaseTest::createUpstreams(); - fake_upstreams_.emplace_back( - new FakeUpstream(createUpstreamSslContext(), 0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back(new FakeUpstream( + createUpstreamSslContext(), 0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } Network::TransportSocketFactoryPtr createUpstreamSslContext() { @@ -651,7 +651,8 @@ class AdsFailIntegrationTest : public AdsIntegrationBaseTest, void createUpstreams() override { AdsIntegrationBaseTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } void initialize() override { @@ -696,7 +697,8 @@ class AdsConfigIntegrationTest : public AdsIntegrationBaseTest, void createUpstreams() override { AdsIntegrationBaseTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } void initialize() override { diff --git a/test/integration/autonomous_upstream.h b/test/integration/autonomous_upstream.h index 989a6c5692951..fde036d214744 100644 --- a/test/integration/autonomous_upstream.h +++ b/test/integration/autonomous_upstream.h @@ -48,8 +48,8 @@ typedef std::unique_ptr AutonomousHttpConnectionPtr; class AutonomousUpstream : public FakeUpstream { public: AutonomousUpstream(uint32_t port, FakeHttpConnection::Type type, - Network::Address::IpVersion version) - : FakeUpstream(port, type, version) {} + Network::Address::IpVersion version, Event::TestTimeSystem& time_system) + : FakeUpstream(port, type, version, time_system) {} ~AutonomousUpstream(); bool createNetworkFilterChain(Network::Connection& connection, diff --git a/test/integration/echo_integration_test.cc b/test/integration/echo_integration_test.cc index d38c2eb131569..8773cb183d889 100644 --- a/test/integration/echo_integration_test.cc +++ b/test/integration/echo_integration_test.cc @@ -10,7 +10,7 @@ std::string echo_config; class EchoIntegrationTest : public BaseIntegrationTest, public testing::TestWithParam { public: - EchoIntegrationTest() : BaseIntegrationTest(GetParam(), echo_config) {} + EchoIntegrationTest() : BaseIntegrationTest(GetParam(), realTime(), echo_config) {} // Called once by the gtest framework before any EchoIntegrationTests are run. static void SetUpTestCase() { diff --git a/test/integration/eds_integration_test.cc b/test/integration/eds_integration_test.cc index ca4af097bb76c..38c2b63b50114 100644 --- a/test/integration/eds_integration_test.cc +++ b/test/integration/eds_integration_test.cc @@ -16,7 +16,8 @@ namespace { class EdsIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - EdsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + EdsIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} // We need to supply the endpoints via EDS to provide health status. Use a // filesystem delivery to simplify test mechanics. diff --git a/test/integration/fake_upstream.cc b/test/integration/fake_upstream.cc index 5851a9aaef5e9..802c440f77e9f 100644 --- a/test/integration/fake_upstream.cc +++ b/test/integration/fake_upstream.cc @@ -37,7 +37,7 @@ using testing::AssertionSuccess; namespace Envoy { FakeStream::FakeStream(FakeHttpConnection& parent, Http::StreamEncoder& encoder, - Event::TimeSystem& time_system) + Event::TestTimeSystem& time_system) : parent_(parent), encoder_(encoder), time_system_(time_system) { encoder.getStream().addCallbacks(*this); } @@ -202,7 +202,7 @@ void FakeStream::finishGrpcStream(Grpc::Status::GrpcStatus status) { FakeHttpConnection::FakeHttpConnection(SharedConnectionWrapper& shared_connection, Stats::Store& store, Type type, - Event::TimeSystem& time_system) + Event::TestTimeSystem& time_system) : FakeConnectionBase(shared_connection, time_system) { if (type == Type::HTTP1) { codec_.reset(new Http::Http1::ServerConnectionImpl(shared_connection_.connection(), *this, @@ -327,11 +327,12 @@ AssertionResult FakeHttpConnection::waitForNewStream(Event::Dispatcher& client_d return AssertionSuccess(); } -FakeUpstream::FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type) +FakeUpstream::FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type, + Event::TestTimeSystem& time_system) : FakeUpstream(Network::Test::createRawBufferSocketFactory(), Network::SocketPtr{new Network::UdsListenSocket( std::make_shared(uds_path))}, - type, false) { + type, time_system, false) { ENVOY_LOG(info, "starting fake server on unix domain socket {}", uds_path); } @@ -343,27 +344,28 @@ static Network::SocketPtr makeTcpListenSocket(uint32_t port, Network::Address::I } FakeUpstream::FakeUpstream(uint32_t port, FakeHttpConnection::Type type, - Network::Address::IpVersion version, bool enable_half_close) + Network::Address::IpVersion version, Event::TestTimeSystem& time_system, + bool enable_half_close) : FakeUpstream(Network::Test::createRawBufferSocketFactory(), - makeTcpListenSocket(port, version), type, enable_half_close) { + makeTcpListenSocket(port, version), type, time_system, enable_half_close) { ENVOY_LOG(info, "starting fake server on port {}. Address version is {}", this->localAddress()->ip()->port(), Network::Test::addressVersionAsString(version)); } FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, uint32_t port, FakeHttpConnection::Type type, - Network::Address::IpVersion version) + Network::Address::IpVersion version, Event::TestTimeSystem& time_system) : FakeUpstream(std::move(transport_socket_factory), makeTcpListenSocket(port, version), type, - false) { + time_system, false) { ENVOY_LOG(info, "starting fake SSL server on port {}. Address version is {}", this->localAddress()->ip()->port(), Network::Test::addressVersionAsString(version)); } FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, Network::SocketPtr&& listen_socket, FakeHttpConnection::Type type, - bool enable_half_close) + Event::TestTimeSystem& time_system, bool enable_half_close) : http_type_(type), socket_(std::move(listen_socket)), api_(new Api::Impl(milliseconds(10000))), - dispatcher_(api_->allocateDispatcher(test_time_.timeSystem())), + time_system_(time_system), dispatcher_(api_->allocateDispatcher(time_system_)), handler_(new Server::ConnectionHandlerImpl(ENVOY_LOGGER(), *dispatcher_)), allow_unexpected_disconnects_(false), enable_half_close_(enable_half_close), listener_(*this), filter_chain_(Network::Test::createEmptyFilterChain(std::move(transport_socket_factory))) { @@ -410,7 +412,7 @@ void FakeUpstream::threadRoutine() { AssertionResult FakeUpstream::waitForHttpConnection(Event::Dispatcher& client_dispatcher, FakeHttpConnectionPtr& connection, milliseconds timeout) { - Event::TimeSystem& time_system = timeSystem(); + Event::TestTimeSystem& time_system = timeSystem(); auto end_time = time_system.monotonicTime() + timeout; { Thread::LockGuard lock(lock_); @@ -455,7 +457,8 @@ FakeUpstream::waitForHttpConnection(Event::Dispatcher& client_dispatcher, client_dispatcher.run(Event::Dispatcher::RunType::NonBlock); } else { connection = std::make_unique( - upstream.consumeConnection(), upstream.stats_store_, upstream.http_type_, time_system); + upstream.consumeConnection(), upstream.stats_store_, upstream.http_type_, + upstream.timeSystem()); lock.release(); VERIFY_ASSERTION(connection->initialize()); VERIFY_ASSERTION(connection->readDisable(false)); diff --git a/test/integration/fake_upstream.h b/test/integration/fake_upstream.h index 311d02c3456d3..721b35d2ac609 100644 --- a/test/integration/fake_upstream.h +++ b/test/integration/fake_upstream.h @@ -29,7 +29,7 @@ #include "common/stats/isolated_store_impl.h" #include "test/test_common/printers.h" -#include "test/test_common/test_time.h" +#include "test/test_common/test_time_system.h" #include "test/test_common/utility.h" namespace Envoy { @@ -43,7 +43,7 @@ class FakeStream : public Http::StreamDecoder, Logger::Loggable { public: FakeStream(FakeHttpConnection& parent, Http::StreamEncoder& encoder, - Event::TimeSystem& time_system); + Event::TestTimeSystem& time_system); uint64_t bodyLength() { return body_.length(); } Buffer::Instance& body() { return body_; } @@ -157,7 +157,7 @@ class FakeStream : public Http::StreamDecoder, virtual void setEndStream(bool end) { end_stream_ = end; } - Event::TimeSystem& timeSystem() { return time_system_; } + Event::TestTimeSystem& timeSystem() { return time_system_; } protected: Http::HeaderMapPtr headers_; @@ -174,7 +174,7 @@ class FakeStream : public Http::StreamDecoder, Grpc::Decoder grpc_decoder_; std::vector decoded_grpc_frames_; bool add_served_by_header_{}; - Event::TimeSystem& time_system_; + Event::TestTimeSystem& time_system_; }; typedef std::unique_ptr FakeStreamPtr; @@ -261,7 +261,9 @@ class SharedConnectionWrapper : public Network::ConnectionCallbacks { } callback_ready_event.notifyOne(); }); - Thread::CondVar::WaitStatus status = callback_ready_event.waitFor(lock_, timeout); + Event::TestTimeSystem& time_system = + dynamic_cast(connection_.dispatcher().timeSystem()); + Thread::CondVar::WaitStatus status = time_system.waitFor(lock_, callback_ready_event, timeout); if (status == Thread::CondVar::WaitStatus::Timeout) { return testing::AssertionFailure() << "Timed out while executing on dispatcher."; } @@ -377,7 +379,7 @@ class FakeConnectionBase : public Logger::Loggable { bool connected() const { return shared_connection_.connected(); } protected: - FakeConnectionBase(SharedConnectionWrapper& shared_connection, Event::TimeSystem& time_system) + FakeConnectionBase(SharedConnectionWrapper& shared_connection, Event::TestTimeSystem& time_system) : shared_connection_(shared_connection), time_system_(time_system) {} Common::CallbackHandle* disconnect_callback_handle_; @@ -386,7 +388,7 @@ class FakeConnectionBase : public Logger::Loggable { Thread::CondVar connection_event_; Thread::MutexBasicLockable lock_; bool half_closed_ GUARDED_BY(lock_){}; - Event::TimeSystem& time_system_; + Event::TestTimeSystem& time_system_; }; /** @@ -397,7 +399,7 @@ class FakeHttpConnection : public Http::ServerConnectionCallbacks, public FakeCo enum class Type { HTTP1, HTTP2 }; FakeHttpConnection(SharedConnectionWrapper& shared_connection, Stats::Store& store, Type type, - Event::TimeSystem& time_system); + Event::TestTimeSystem& time_system); // By default waitForNewStream assumes the next event is a new stream and // returns AssertionFaliure if an unexpected event occurs. If a caller truly @@ -437,7 +439,7 @@ typedef std::unique_ptr FakeHttpConnectionPtr; */ class FakeRawConnection : public FakeConnectionBase { public: - FakeRawConnection(SharedConnectionWrapper& shared_connection, Event::TimeSystem& time_system) + FakeRawConnection(SharedConnectionWrapper& shared_connection, Event::TestTimeSystem& time_system) : FakeConnectionBase(shared_connection, time_system) {} typedef const std::function ValidatorFunction; @@ -504,11 +506,13 @@ class FakeUpstream : Logger::Loggable, public Network::FilterChainManager, public Network::FilterChainFactory { public: - FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type); + FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type, + Event::TestTimeSystem& time_system); FakeUpstream(uint32_t port, FakeHttpConnection::Type type, Network::Address::IpVersion version, - bool enable_half_close = false); + Event::TestTimeSystem& time_system, bool enable_half_close = false); FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, uint32_t port, - FakeHttpConnection::Type type, Network::Address::IpVersion version); + FakeHttpConnection::Type type, Network::Address::IpVersion version, + Event::TestTimeSystem& time_system); ~FakeUpstream(); FakeHttpConnection::Type httpType() { return http_type_; } @@ -545,7 +549,7 @@ class FakeUpstream : Logger::Loggable, bool createListenerFilterChain(Network::ListenerFilterManager& listener) override; void set_allow_unexpected_disconnects(bool value) { allow_unexpected_disconnects_ = value; } - Event::TimeSystem& timeSystem() { return dispatcher_->timeSystem(); } + Event::TestTimeSystem& timeSystem() { return time_system_; } // Stops the dispatcher loop and joins the listening thread. void cleanUp(); @@ -557,7 +561,7 @@ class FakeUpstream : Logger::Loggable, private: FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, Network::SocketPtr&& connection, FakeHttpConnection::Type type, - bool enable_half_close); + Event::TestTimeSystem& time_system, bool enable_half_close); class FakeListener : public Network::ListenerConfig { public: @@ -590,7 +594,7 @@ class FakeUpstream : Logger::Loggable, Thread::ThreadPtr thread_; Thread::CondVar new_connection_event_; Api::ApiPtr api_; - DangerousDeprecatedTestTime test_time_; + Event::TestTimeSystem& time_system_; Event::DispatcherPtr dispatcher_; Network::ConnectionHandlerPtr handler_; std::list new_connections_ GUARDED_BY(lock_); diff --git a/test/integration/h1_fuzz.h b/test/integration/h1_fuzz.h index 5fec0263a3f30..051f12a53e66e 100644 --- a/test/integration/h1_fuzz.h +++ b/test/integration/h1_fuzz.h @@ -12,7 +12,7 @@ namespace Envoy { class H1FuzzIntegrationTest : public HttpIntegrationTest { public: H1FuzzIntegrationTest(Network::Address::IpVersion version) - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, version) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, version, realTime()) {} void initialize() override; void replay(const test::integration::CaptureFuzzTestCase&); diff --git a/test/integration/hds_integration_test.cc b/test/integration/hds_integration_test.cc index f64c0924be718..258347c7a40b5 100644 --- a/test/integration/hds_integration_test.cc +++ b/test/integration/hds_integration_test.cc @@ -24,10 +24,12 @@ namespace { class HdsIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - HdsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + HdsIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void createUpstreams() override { - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); hds_upstream_ = fake_upstreams_.back().get(); hds_upstream_->set_allow_unexpected_disconnects(true); HttpIntegrationTest::createUpstreams(); @@ -52,8 +54,10 @@ class HdsIntegrationTest : public HttpIntegrationTest, HttpIntegrationTest::initialize(); // Endpoint connections - host_upstream_.reset(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); - host2_upstream_.reset(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + host_upstream_.reset( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); + host2_upstream_.reset( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); } // Sets up a connection between Envoy and the management server. diff --git a/test/integration/header_integration_test.cc b/test/integration/header_integration_test.cc index a1f5fe7b51cc7..1ebd4fa1c43ab 100644 --- a/test/integration/header_integration_test.cc +++ b/test/integration/header_integration_test.cc @@ -154,7 +154,7 @@ class HeaderIntegrationTest public testing::TestWithParam> { public: HeaderIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam())) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam()), realTime()) {} bool routerSuppressEnvoyHeaders() const { return std::get<1>(GetParam()); } @@ -333,7 +333,8 @@ class HeaderIntegrationTest HttpIntegrationTest::createUpstreams(); if (use_eds_) { - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } } diff --git a/test/integration/http2_integration_test.cc b/test/integration/http2_integration_test.cc index fdfb8dc3464a5..60f5c30e9d084 100644 --- a/test/integration/http2_integration_test.cc +++ b/test/integration/http2_integration_test.cc @@ -474,7 +474,8 @@ Http2RingHashIntegrationTest::~Http2RingHashIntegrationTest() { void Http2RingHashIntegrationTest::createUpstreams() { for (int i = 0; i < num_upstreams_; i++) { - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); } } diff --git a/test/integration/http2_integration_test.h b/test/integration/http2_integration_test.h index 9bc7629773c3b..62c410a24dc0a 100644 --- a/test/integration/http2_integration_test.h +++ b/test/integration/http2_integration_test.h @@ -8,7 +8,8 @@ namespace Envoy { class Http2IntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - Http2IntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam()) {} + Http2IntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam(), realTime()) {} void SetUp() override { setDownstreamProtocol(Http::CodecClient::Type::HTTP2); } diff --git a/test/integration/http2_upstream_integration_test.h b/test/integration/http2_upstream_integration_test.h index 877f940e9f410..4a7779580bc26 100644 --- a/test/integration/http2_upstream_integration_test.h +++ b/test/integration/http2_upstream_integration_test.h @@ -9,7 +9,7 @@ class Http2UpstreamIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: Http2UpstreamIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam()) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam(), realTime()) {} void SetUp() override { setDownstreamProtocol(Http::CodecClient::Type::HTTP2); diff --git a/test/integration/http_integration.cc b/test/integration/http_integration.cc index a297ca3b52657..e0c99c249e3d4 100644 --- a/test/integration/http_integration.cc +++ b/test/integration/http_integration.cc @@ -213,8 +213,9 @@ HttpIntegrationTest::makeHttpConnection(Network::ClientConnectionPtr&& conn) { HttpIntegrationTest::HttpIntegrationTest(Http::CodecClient::Type downstream_protocol, Network::Address::IpVersion version, - const std::string& config) - : BaseIntegrationTest(version, config), downstream_protocol_(downstream_protocol) { + TestTimeSystemPtr time_system, const std::string& config) + : BaseIntegrationTest(version, std::move(time_system), config), + downstream_protocol_(downstream_protocol) { // Legacy integration tests expect the default listener to be named "http" for lookupPort calls. config_helper_.renameListener("http"); config_helper_.setClientCodec(typeToCodecType(downstream_protocol_)); diff --git a/test/integration/http_integration.h b/test/integration/http_integration.h index 24a7a5d7cb2ef..30e2eb905e835 100644 --- a/test/integration/http_integration.h +++ b/test/integration/http_integration.h @@ -78,7 +78,7 @@ typedef std::unique_ptr IntegrationCodecClientPtr; class HttpIntegrationTest : public BaseIntegrationTest { public: HttpIntegrationTest(Http::CodecClient::Type downstream_protocol, - Network::Address::IpVersion version, + Network::Address::IpVersion version, TestTimeSystemPtr time_system, const std::string& config = ConfigHelper::HTTP_PROXY_CONFIG); virtual ~HttpIntegrationTest(); diff --git a/test/integration/http_protocol_integration.h b/test/integration/http_protocol_integration.h index 07a014809aa30..5b2ede1df9809 100644 --- a/test/integration/http_protocol_integration.h +++ b/test/integration/http_protocol_integration.h @@ -49,7 +49,7 @@ class HttpProtocolIntegrationTest : public HttpIntegrationTest, protocolTestParamsToString(const testing::TestParamInfo& p); HttpProtocolIntegrationTest() - : HttpIntegrationTest(GetParam().downstream_protocol, GetParam().version) {} + : HttpIntegrationTest(GetParam().downstream_protocol, GetParam().version, realTime()) {} void SetUp() override { setDownstreamProtocol(GetParam().downstream_protocol); diff --git a/test/integration/integration.cc b/test/integration/integration.cc index 1e849f2a4d74c..3c3849606ec25 100644 --- a/test/integration/integration.cc +++ b/test/integration/integration.cc @@ -211,10 +211,10 @@ void IntegrationTcpClient::ConnectionCallbacks::onEvent(Network::ConnectionEvent } BaseIntegrationTest::BaseIntegrationTest(Network::Address::IpVersion version, - const std::string& config) + TestTimeSystemPtr time_system, const std::string& config) : api_(new Api::Impl(std::chrono::milliseconds(10000))), - mock_buffer_factory_(new NiceMock), - dispatcher_(new Event::DispatcherImpl(test_time_.timeSystem(), + mock_buffer_factory_(new NiceMock), time_system_(std::move(time_system)), + dispatcher_(new Event::DispatcherImpl(*time_system_, Buffer::WatermarkFactoryPtr{mock_buffer_factory_})), version_(version), config_helper_(version, config), default_log_level_(TestEnvironment::getOptions().logLevel()) { @@ -224,7 +224,7 @@ BaseIntegrationTest::BaseIntegrationTest(Network::Address::IpVersion version, // notification and clear the pool connection if necessary. A real fix would require adding fairly // complex test hooks to the server and/or spin waiting on stats, neither of which I think are // necessary right now. - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + time_system_->sleep(std::chrono::milliseconds(10)); ON_CALL(*mock_buffer_factory_, create_(_, _)) .WillByDefault(Invoke([](std::function below_low, std::function above_high) -> Buffer::Instance* { @@ -254,10 +254,11 @@ void BaseIntegrationTest::initialize() { void BaseIntegrationTest::createUpstreams() { for (uint32_t i = 0; i < fake_upstreams_count_; ++i) { if (autonomous_upstream_) { - fake_upstreams_.emplace_back(new AutonomousUpstream(0, upstream_protocol_, version_)); + fake_upstreams_.emplace_back( + new AutonomousUpstream(0, upstream_protocol_, version_, *time_system_)); } else { fake_upstreams_.emplace_back( - new FakeUpstream(0, upstream_protocol_, version_, enable_half_close_)); + new FakeUpstream(0, upstream_protocol_, version_, *time_system_, enable_half_close_)); } } } @@ -341,8 +342,8 @@ void BaseIntegrationTest::registerTestServerPorts(const std::vector void BaseIntegrationTest::createGeneratedApiTestServer(const std::string& bootstrap_path, const std::vector& port_names) { - test_server_ = IntegrationTestServer::create(bootstrap_path, version_, - pre_worker_start_test_steps_, deterministic_); + test_server_ = IntegrationTestServer::create( + bootstrap_path, version_, pre_worker_start_test_steps_, deterministic_, *time_system_); if (config_helper_.bootstrap().static_resources().listeners_size() > 0) { // Wait for listeners to be created before invoking registerTestServerPorts() below, as that // needs to know about the bound listener ports. @@ -372,7 +373,7 @@ void BaseIntegrationTest::createTestServer(const std::string& json_path, const std::vector& port_names) { test_server_ = IntegrationTestServer::create( TestEnvironment::temporaryFileSubstitute(json_path, port_map_, version_), version_, nullptr, - deterministic_); + deterministic_, *time_system_); registerTestServerPorts(port_names); } diff --git a/test/integration/integration.h b/test/integration/integration.h index 59273d39a2854..f5827a35e7c14 100644 --- a/test/integration/integration.h +++ b/test/integration/integration.h @@ -14,6 +14,7 @@ #include "test/mocks/buffer/mocks.h" #include "test/test_common/environment.h" #include "test/test_common/printers.h" +#include "test/test_common/simulated_time_system.h" #include "test/test_common/test_time.h" #include "spdlog/spdlog.h" @@ -119,10 +120,31 @@ struct ApiFilesystemConfig { */ class BaseIntegrationTest : Logger::Loggable { public: - BaseIntegrationTest(Network::Address::IpVersion version, + using TestTimeSystemPtr = std::unique_ptr; + + BaseIntegrationTest(Network::Address::IpVersion version, TestTimeSystemPtr time_system, const std::string& config = ConfigHelper::HTTP_PROXY_CONFIG); + + // TODO(jmarantz): this alternate constructor is a temporary hack to allow + // envoy-filter-example/echo2_integration_test.cc to compile so CI for #4512 + // can pass. Once that passes, we can up update filter-examples so it can see + // the 3-arg version of BaseIntegrationTest, and remove this constructor + // variant. + BaseIntegrationTest(Network::Address::IpVersion version, const std::string& config) + : BaseIntegrationTest(version, realTime(), config) {} + virtual ~BaseIntegrationTest() {} + /** + * Helper function to create a simulated time integration test during construction. + */ + static TestTimeSystemPtr simTime() { return std::make_unique(); } + + /** + * Helper function to create a wall-clock time integration test during construction. + */ + static TestTimeSystemPtr realTime() { return std::make_unique(); } + // Initialize the basic proto configuration, create fake upstreams, and start Envoy. virtual void initialize(); // Set up the fake upstream connections. This is called by initialize() and @@ -158,10 +180,14 @@ class BaseIntegrationTest : Logger::Loggable { void createApiTestServer(const ApiFilesystemConfig& api_filesystem_config, const std::vector& port_names); - Api::ApiPtr api_; - DangerousDeprecatedTestTime test_time_; + Event::TestTimeSystem& timeSystem() { return *time_system_; } + Api::ApiPtr api_; MockBufferFactory* mock_buffer_factory_; // Will point to the dispatcher's factory. +private: + TestTimeSystemPtr time_system_; + +public: Event::DispatcherPtr dispatcher_; /** diff --git a/test/integration/integration_admin_test.cc b/test/integration/integration_admin_test.cc index 7167fca9ea0a8..075f6136451d1 100644 --- a/test/integration/integration_admin_test.cc +++ b/test/integration/integration_admin_test.cc @@ -414,7 +414,8 @@ TEST_P(IntegrationAdminTest, AdminCpuProfilerStart) { class IntegrationAdminIpv4Ipv6Test : public HttpIntegrationTest, public testing::Test { public: IntegrationAdminIpv4Ipv6Test() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, Network::Address::IpVersion::v4) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, Network::Address::IpVersion::v4, + realTime()) {} void initialize() override { config_helper_.addConfigModifier( diff --git a/test/integration/integration_admin_test.h b/test/integration/integration_admin_test.h index c72f4e1cc5f3a..3a0487d7d60e2 100644 --- a/test/integration/integration_admin_test.h +++ b/test/integration/integration_admin_test.h @@ -11,7 +11,8 @@ namespace Envoy { class IntegrationAdminTest : public HttpIntegrationTest, public testing::TestWithParam { public: - IntegrationAdminTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + IntegrationAdminTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override { config_helper_.addFilter(ConfigHelper::DEFAULT_HEALTH_CHECK_FILTER); diff --git a/test/integration/integration_test.h b/test/integration/integration_test.h index 7ae0e934e7855..96f17288e1712 100644 --- a/test/integration/integration_test.h +++ b/test/integration/integration_test.h @@ -8,6 +8,6 @@ namespace Envoy { class IntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - IntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + IntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} }; } // namespace Envoy diff --git a/test/integration/legacy_json_integration_test.cc b/test/integration/legacy_json_integration_test.cc index 1a288fdb2a8d9..d5663e4a509d3 100644 --- a/test/integration/legacy_json_integration_test.cc +++ b/test/integration/legacy_json_integration_test.cc @@ -12,14 +12,17 @@ namespace Envoy { class LegacyJsonIntegrationTest : public BaseIntegrationTest, public testing::TestWithParam { public: - LegacyJsonIntegrationTest() : BaseIntegrationTest(GetParam()) {} + LegacyJsonIntegrationTest() : BaseIntegrationTest(GetParam(), realTime()) {} void SetUp() override { - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); registerPort("upstream_0", fake_upstreams_.back()->localAddress()->ip()->port()); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); registerPort("upstream_1", fake_upstreams_.back()->localAddress()->ip()->port()); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); registerPort("cluster_with_buffer_limits", fake_upstreams_.back()->localAddress()->ip()->port()); } @@ -59,7 +62,7 @@ TEST_P(LegacyJsonIntegrationTest, TestServerXfc) { param_map["set_current_client_cert_details"] = ""; std::string config = TestEnvironment::temporaryFileSubstitute( "test/config/integration/server_xfcc.json", param_map, port_map_, version_); - IntegrationTestServer::create(config, version_, nullptr, false); + IntegrationTestServer::create(config, version_, nullptr, false, timeSystem()); } TEST_P(LegacyJsonIntegrationTest, TestEchoServer) { diff --git a/test/integration/load_stats_integration_test.cc b/test/integration/load_stats_integration_test.cc index cb848247302c0..949dd8a96fdda 100644 --- a/test/integration/load_stats_integration_test.cc +++ b/test/integration/load_stats_integration_test.cc @@ -18,7 +18,8 @@ namespace { class LoadStatsIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - LoadStatsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) { + LoadStatsIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) { // We rely on some fairly specific load balancing picks in this test, so // determinizie the schedule. setDeterministic(); @@ -96,7 +97,8 @@ class LoadStatsIntegrationTest : public HttpIntegrationTest, } void createUpstreams() override { - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); load_report_upstream_ = fake_upstreams_.back().get(); HttpIntegrationTest::createUpstreams(); } diff --git a/test/integration/proxy_proto_integration_test.h b/test/integration/proxy_proto_integration_test.h index 6792abc5cc1d0..d12badf470ad2 100644 --- a/test/integration/proxy_proto_integration_test.h +++ b/test/integration/proxy_proto_integration_test.h @@ -12,7 +12,8 @@ namespace Envoy { class ProxyProtoIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - ProxyProtoIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) { + ProxyProtoIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) { config_helper_.addConfigModifier( [&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void { auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0); diff --git a/test/integration/ratelimit_integration_test.cc b/test/integration/ratelimit_integration_test.cc index 02cbbaae183e1..b81ee37a65b19 100644 --- a/test/integration/ratelimit_integration_test.cc +++ b/test/integration/ratelimit_integration_test.cc @@ -34,13 +34,15 @@ class RatelimitGrpcClientIntegrationParamTest class RatelimitIntegrationTest : public HttpIntegrationTest, public RatelimitGrpcClientIntegrationParamTest { public: - RatelimitIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion()) {} + RatelimitIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion(), realTime()) {} void SetUp() override { initialize(); } void createUpstreams() override { HttpIntegrationTest::createUpstreams(); - fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_)); + fake_upstreams_.emplace_back( + new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, timeSystem())); } void initialize() override { diff --git a/test/integration/sds_dynamic_integration_test.cc b/test/integration/sds_dynamic_integration_test.cc index af0a34a6a20dd..05de52f258d0f 100644 --- a/test/integration/sds_dynamic_integration_test.cc +++ b/test/integration/sds_dynamic_integration_test.cc @@ -43,7 +43,7 @@ class SdsDynamicIntegrationBaseTest : public HttpIntegrationTest, public Grpc::GrpcClientIntegrationParamTest { public: SdsDynamicIntegrationBaseTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion()), + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, ipVersion(), realTime()), server_cert_("server_cert"), validation_secret_("validation_secret"), client_cert_("client_cert") {} @@ -179,8 +179,8 @@ class SdsDynamicDownstreamIntegrationTest : public SdsDynamicIntegrationBaseTest void createUpstreams() override { HttpIntegrationTest::createUpstreams(); // SDS upstream - fake_upstreams_.emplace_back( - new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, enable_half_close_)); + fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, + timeSystem(), enable_half_close_)); } void TearDown() override { @@ -352,10 +352,11 @@ class SdsDynamicUpstreamIntegrationTest : public SdsDynamicIntegrationBaseTest { void createUpstreams() override { // This is for backend with ssl fake_upstreams_.emplace_back(new FakeUpstream(createUpstreamSslContext(context_manager_), 0, - FakeHttpConnection::Type::HTTP1, version_)); + FakeHttpConnection::Type::HTTP1, version_, + timeSystem())); // This is sds. - fake_upstreams_.emplace_back( - new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, enable_half_close_)); + fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2, version_, + timeSystem(), enable_half_close_)); } }; diff --git a/test/integration/sds_static_integration_test.cc b/test/integration/sds_static_integration_test.cc index f7551a751cd2e..499cc36c322bb 100644 --- a/test/integration/sds_static_integration_test.cc +++ b/test/integration/sds_static_integration_test.cc @@ -36,7 +36,7 @@ class SdsStaticDownstreamIntegrationTest public testing::TestWithParam { public: SdsStaticDownstreamIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override { config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { @@ -112,7 +112,7 @@ class SdsStaticUpstreamIntegrationTest public testing::TestWithParam { public: SdsStaticUpstreamIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override { config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { @@ -148,7 +148,8 @@ class SdsStaticUpstreamIntegrationTest void createUpstreams() override { fake_upstreams_.emplace_back(new FakeUpstream(createUpstreamSslContext(context_manager_), 0, - FakeHttpConnection::Type::HTTP1, version_)); + FakeHttpConnection::Type::HTTP1, version_, + timeSystem())); } private: diff --git a/test/integration/server.cc b/test/integration/server.cc index 2cb73966a31fd..47934e118f217 100644 --- a/test/integration/server.cc +++ b/test/integration/server.cc @@ -22,10 +22,12 @@ namespace Envoy { -IntegrationTestServerPtr IntegrationTestServer::create( - const std::string& config_path, const Network::Address::IpVersion version, - std::function pre_worker_start_test_steps, bool deterministic) { - IntegrationTestServerPtr server{new IntegrationTestServer(config_path)}; +IntegrationTestServerPtr +IntegrationTestServer::create(const std::string& config_path, + const Network::Address::IpVersion version, + std::function pre_worker_start_test_steps, bool deterministic, + Event::TestTimeSystem& time_system) { + IntegrationTestServerPtr server{new IntegrationTestServer(time_system, config_path)}; server->start(version, pre_worker_start_test_steps, deterministic); return server; } @@ -104,8 +106,8 @@ void IntegrationTestServer::threadRoutine(const Network::Address::IpVersion vers random_generator = std::make_unique(); } server_.reset(new Server::InstanceImpl( - options, test_time_.timeSystem(), Network::Utility::getLocalAddress(version), *this, - restarter, stats_store, lock, *this, std::move(random_generator), tls)); + options, time_system_, Network::Utility::getLocalAddress(version), *this, restarter, + stats_store, lock, *this, std::move(random_generator), tls)); pending_listeners_ = server_->listenerManager().listeners().size(); ENVOY_LOG(info, "waiting for {} test server listeners", pending_listeners_); // This is technically thread unsafe (assigning to a shared_ptr accessed diff --git a/test/integration/server.h b/test/integration/server.h index 83dd44635df06..cbf94e56805a4 100644 --- a/test/integration/server.h +++ b/test/integration/server.h @@ -19,7 +19,7 @@ #include "server/test_hooks.h" #include "test/integration/server_stats.h" -#include "test/test_common/test_time.h" +#include "test/test_common/test_time_system.h" #include "test/test_common/utility.h" namespace Envoy { @@ -222,7 +222,7 @@ class IntegrationTestServer : Logger::Loggable, static IntegrationTestServerPtr create(const std::string& config_path, const Network::Address::IpVersion version, std::function pre_worker_start_test_steps, - bool deterministic); + bool deterministic, Event::TestTimeSystem& time_system); ~IntegrationTestServer(); Server::TestDrainManager& drainManager() { return *drain_manager_; } @@ -241,19 +241,19 @@ class IntegrationTestServer : Logger::Loggable, void waitForCounterGe(const std::string& name, uint64_t value) override { while (counter(name) == nullptr || counter(name)->value() < value) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + time_system_.sleep(std::chrono::milliseconds(10)); } } void waitForGaugeGe(const std::string& name, uint64_t value) override { while (gauge(name) == nullptr || gauge(name)->value() < value) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + time_system_.sleep(std::chrono::milliseconds(10)); } } void waitForGaugeEq(const std::string& name, uint64_t value) override { while (gauge(name) == nullptr || gauge(name)->value() != value) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + time_system_.sleep(std::chrono::milliseconds(10)); } } @@ -288,7 +288,8 @@ class IntegrationTestServer : Logger::Loggable, } protected: - IntegrationTestServer(const std::string& config_path) : config_path_(config_path) {} + IntegrationTestServer(Event::TestTimeSystem& time_system, const std::string& config_path) + : time_system_(time_system), config_path_(config_path) {} private: /** @@ -296,12 +297,12 @@ class IntegrationTestServer : Logger::Loggable, */ void threadRoutine(const Network::Address::IpVersion version, bool deterministic); + Event::TestTimeSystem& time_system_; const std::string config_path_; Thread::ThreadPtr thread_; Thread::CondVar listeners_cv_; Thread::MutexBasicLockable listeners_mutex_; uint64_t pending_listeners_; - DangerousDeprecatedTestTime test_time_; ConditionalInitializer server_set_; std::unique_ptr server_; Server::TestDrainManager* drain_manager_{}; diff --git a/test/integration/ssl_integration_test.h b/test/integration/ssl_integration_test.h index a883d3b9c3cb8..c0411e2a723b8 100644 --- a/test/integration/ssl_integration_test.h +++ b/test/integration/ssl_integration_test.h @@ -19,7 +19,8 @@ namespace Ssl { class SslIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - SslIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + SslIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override; diff --git a/test/integration/stats_integration_test.cc b/test/integration/stats_integration_test.cc index eb254414df9b0..788a4a907ea17 100644 --- a/test/integration/stats_integration_test.cc +++ b/test/integration/stats_integration_test.cc @@ -15,7 +15,7 @@ namespace { class StatsIntegrationTest : public BaseIntegrationTest, public testing::TestWithParam { public: - StatsIntegrationTest() : BaseIntegrationTest(GetParam()) {} + StatsIntegrationTest() : BaseIntegrationTest(GetParam(), realTime()) {} void TearDown() override { test_server_.reset(); diff --git a/test/integration/tcp_conn_pool_integration_test.cc b/test/integration/tcp_conn_pool_integration_test.cc index fbe93d877c9a4..e4905962c959f 100644 --- a/test/integration/tcp_conn_pool_integration_test.cc +++ b/test/integration/tcp_conn_pool_integration_test.cc @@ -115,7 +115,8 @@ class TcpConnPoolIntegrationTest : public BaseIntegrationTest, public testing::TestWithParam { public: TcpConnPoolIntegrationTest() - : BaseIntegrationTest(GetParam(), tcp_conn_pool_config), filter_resolver_(config_factory_) {} + : BaseIntegrationTest(GetParam(), realTime(), tcp_conn_pool_config), + filter_resolver_(config_factory_) {} // Called once by the gtest framework before any tests are run. static void SetUpTestCase() { diff --git a/test/integration/tcp_proxy_integration_test.h b/test/integration/tcp_proxy_integration_test.h index 0c50ed6f3ae9d..2ab4b5424a4d9 100644 --- a/test/integration/tcp_proxy_integration_test.h +++ b/test/integration/tcp_proxy_integration_test.h @@ -14,7 +14,8 @@ namespace { class TcpProxyIntegrationTest : public BaseIntegrationTest, public testing::TestWithParam { public: - TcpProxyIntegrationTest() : BaseIntegrationTest(GetParam(), ConfigHelper::TCP_PROXY_CONFIG) { + TcpProxyIntegrationTest() + : BaseIntegrationTest(GetParam(), realTime(), ConfigHelper::TCP_PROXY_CONFIG) { enable_half_close_ = true; } diff --git a/test/integration/uds_integration_test.h b/test/integration/uds_integration_test.h index a667be59039e0..85891bd18d98d 100644 --- a/test/integration/uds_integration_test.h +++ b/test/integration/uds_integration_test.h @@ -19,13 +19,13 @@ class UdsUpstreamIntegrationTest public testing::TestWithParam> { public: UdsUpstreamIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam())), + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam()), realTime()), abstract_namespace_(std::get<1>(GetParam())) {} void createUpstreams() override { fake_upstreams_.emplace_back(new FakeUpstream( TestEnvironment::unixDomainSocketPath("udstest.1.sock", abstract_namespace_), - FakeHttpConnection::Type::HTTP1)); + FakeHttpConnection::Type::HTTP1, timeSystem())); config_helper_.addConfigModifier( [&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void { @@ -50,7 +50,7 @@ class UdsListenerIntegrationTest public testing::TestWithParam> { public: UdsListenerIntegrationTest() - : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam())), + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, std::get<0>(GetParam()), realTime()), abstract_namespace_(std::get<1>(GetParam())) {} void initialize() override; diff --git a/test/integration/websocket_integration_test.h b/test/integration/websocket_integration_test.h index 69f9c2530ff15..1cedb53781282 100644 --- a/test/integration/websocket_integration_test.h +++ b/test/integration/websocket_integration_test.h @@ -17,7 +17,7 @@ class WebsocketIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: WebsocketIntegrationTest() - : HttpIntegrationTest(GetParam().downstream_protocol, GetParam().version) {} + : HttpIntegrationTest(GetParam().downstream_protocol, GetParam().version, realTime()) {} void initialize() override; void SetUp() override { setDownstreamProtocol(GetParam().downstream_protocol); diff --git a/test/integration/xds_integration_test.cc b/test/integration/xds_integration_test.cc index 27222499b1e45..f0fb4d5d20432 100644 --- a/test/integration/xds_integration_test.cc +++ b/test/integration/xds_integration_test.cc @@ -10,7 +10,8 @@ namespace { class XdsIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam { public: - XdsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam()) { + XdsIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam(), realTime()) { setUpstreamProtocol(FakeHttpConnection::Type::HTTP2); } diff --git a/test/integration/xfcc_integration_test.cc b/test/integration/xfcc_integration_test.cc index 0d81e51bfa8d5..583a1f3642642 100644 --- a/test/integration/xfcc_integration_test.cc +++ b/test/integration/xfcc_integration_test.cc @@ -100,8 +100,8 @@ Network::ClientConnectionPtr XfccIntegrationTest::makeMtlsClientConnection() { } void XfccIntegrationTest::createUpstreams() { - fake_upstreams_.emplace_back( - new FakeUpstream(createUpstreamSslContext(), 0, FakeHttpConnection::Type::HTTP1, version_)); + fake_upstreams_.emplace_back(new FakeUpstream( + createUpstreamSslContext(), 0, FakeHttpConnection::Type::HTTP1, version_, timeSystem())); } void XfccIntegrationTest::initialize() { diff --git a/test/integration/xfcc_integration_test.h b/test/integration/xfcc_integration_test.h index d8302ea05816e..2da01704c2303 100644 --- a/test/integration/xfcc_integration_test.h +++ b/test/integration/xfcc_integration_test.h @@ -31,7 +31,8 @@ class XfccIntegrationTest : public HttpIntegrationTest, const std::string client_uri_san_ = "URI=spiffe://lyft.com/frontend-team"; const std::string client_dns_san_ = "DNS=lyft.com;DNS=www.lyft.com"; - XfccIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} + XfccIntegrationTest() + : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam(), realTime()) {} void initialize() override; void createUpstreams() override; diff --git a/test/mocks/api/BUILD b/test/mocks/api/BUILD index 1ffcdd3a1f053..6a5be0ab4f1e5 100644 --- a/test/mocks/api/BUILD +++ b/test/mocks/api/BUILD @@ -18,5 +18,6 @@ envoy_cc_mock( "//source/common/api:os_sys_calls_lib", "//source/common/common:assert_lib", "//test/mocks/filesystem:filesystem_mocks", + "//test/test_common:test_time_system_interface", ], ) diff --git a/test/mocks/api/mocks.h b/test/mocks/api/mocks.h index f8cd0aca1a640..4f0ae32a9bdfb 100644 --- a/test/mocks/api/mocks.h +++ b/test/mocks/api/mocks.h @@ -12,6 +12,7 @@ #include "common/api/os_sys_calls_impl.h" #include "test/mocks/filesystem/mocks.h" +#include "test/test_common/test_time_system.h" #include "gmock/gmock.h" diff --git a/test/mocks/server/mocks.h b/test/mocks/server/mocks.h index 5ce2366e61717..101f527a6febc 100644 --- a/test/mocks/server/mocks.h +++ b/test/mocks/server/mocks.h @@ -329,7 +329,7 @@ class MockInstance : public Instance { MOCK_METHOD0(httpTracer, Tracing::HttpTracer&()); MOCK_METHOD0(threadLocal, ThreadLocal::Instance&()); MOCK_METHOD0(localInfo, const LocalInfo::LocalInfo&()); - MOCK_METHOD0(timeSystem, Event::TimeSystem&()); + MOCK_METHOD0(timeSystem, Event::TestTimeSystem&()); MOCK_CONST_METHOD0(statsFlushInterval, std::chrono::milliseconds()); std::unique_ptr secret_manager_; diff --git a/test/test_common/test_time.h b/test/test_common/test_time.h index 15b91e3830e5f..5f7501305b440 100644 --- a/test/test_common/test_time.h +++ b/test/test_common/test_time.h @@ -39,7 +39,7 @@ class DangerousDeprecatedTestTime { public: DangerousDeprecatedTestTime(); - Event::TimeSystem& timeSystem() { return time_system_; } + Event::TestTimeSystem& timeSystem() { return time_system_; } private: Event::TestRealTimeSystem time_system_;