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
12 changes: 7 additions & 5 deletions test/common/grpc/grpc_client_integration_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest {

virtual void initialize() {
if (fake_upstream_ == nullptr) {
fake_upstream_ = std::make_unique<FakeUpstream>(0, FakeHttpConnection::Type::HTTP2,
ipVersion(), test_time_.timeSystem());
FakeUpstreamConfig config(test_time_.timeSystem());
config.upstream_protocol_ = FakeHttpConnection::Type::HTTP2;
fake_upstream_ = std::make_unique<FakeUpstream>(0, ipVersion(), config);
}
switch (clientType()) {
case ClientType::EnvoyGrpc:
Expand Down Expand Up @@ -525,9 +526,10 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
std::move(cfg), context_manager_, *stats_store_);
async_client_transport_socket_ =
mock_host_description_->socket_factory_->createTransportSocket(nullptr);
fake_upstream_ = std::make_unique<FakeUpstream>(createUpstreamSslContext(), 0,
FakeHttpConnection::Type::HTTP2, ipVersion(),
test_time_.timeSystem());
FakeUpstreamConfig config(test_time_.timeSystem());
config.upstream_protocol_ = FakeHttpConnection::Type::HTTP2;
fake_upstream_ =
std::make_unique<FakeUpstream>(createUpstreamSslContext(), 0, ipVersion(), config);

GrpcClientIntegrationTest::initialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ name: listener_1
}

void setup(uint32_t upstream_count) {
udp_fake_upstream_ = true;
setUdpFakeUpstream(true);
if (upstream_count > 1) {
setDeterministic();
setUpstreamCount(upstream_count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UdpProxyIntegrationTest : public testing::TestWithParam<Network::Address::
}

void setup(uint32_t upstream_count) {
udp_fake_upstream_ = true;
setUdpFakeUpstream(true);
if (upstream_count > 1) {
setDeterministic();
setUpstreamCount(upstream_count);
Expand Down
9 changes: 5 additions & 4 deletions test/integration/alpn_selection_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ require_client_certificate: true

void createUpstreams() override {
auto endpoint = upstream_address_fn_(0);
fake_upstreams_.emplace_back(new FakeUpstream(
createUpstreamSslContext(), endpoint->ip()->port(),
use_h2_ ? FakeHttpConnection::Type::HTTP2 : FakeHttpConnection::Type::HTTP1,
endpoint->ip()->version(), timeSystem()));
FakeUpstreamConfig config = upstreamConfig();
config.upstream_protocol_ =
use_h2_ ? FakeHttpConnection::Type::HTTP2 : FakeHttpConnection::Type::HTTP1;
fake_upstreams_.emplace_back(
new FakeUpstream(createUpstreamSslContext(), endpoint->ip()->port(), version_, config));
}

bool use_h2_{};
Expand Down
12 changes: 5 additions & 7 deletions test/integration/autonomous_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ using AutonomousHttpConnectionPtr = std::unique_ptr<AutonomousHttpConnection>;
class AutonomousUpstream : public FakeUpstream {
public:
AutonomousUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, Event::TestTimeSystem& time_system,
bool allow_incomplete_streams)
: FakeUpstream(address, type, time_system),
allow_incomplete_streams_(allow_incomplete_streams),
const FakeUpstreamConfig& config, bool allow_incomplete_streams)
: FakeUpstream(address, config), allow_incomplete_streams_(allow_incomplete_streams),
response_trailers_(std::make_unique<Http::TestResponseTrailerMapImpl>()),
response_headers_(std::make_unique<Http::TestResponseHeaderMapImpl>(
Http::TestResponseHeaderMapImpl({{":status", "200"}}))) {}

AutonomousUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, uint32_t port,
FakeHttpConnection::Type type, Network::Address::IpVersion version,
Event::TestTimeSystem& time_system, bool allow_incomplete_streams)
: FakeUpstream(std::move(transport_socket_factory), port, type, version, time_system),
Network::Address::IpVersion version, const FakeUpstreamConfig& config,
bool allow_incomplete_streams)
: FakeUpstream(std::move(transport_socket_factory), port, version, config),
allow_incomplete_streams_(allow_incomplete_streams),
response_trailers_(std::make_unique<Http::TestResponseTrailerMapImpl>()),
response_headers_(std::make_unique<Http::TestResponseHeaderMapImpl>(
Expand Down
17 changes: 7 additions & 10 deletions test/integration/base_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ Network::TransportSocketFactoryPtr BaseIntegrationTest::createUpstreamTlsContext
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamkey.pem"),
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem"));
TestUtility::loadFromYaml(yaml, tls_context);
if (upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
if (upstream_config_.upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
tls_context.mutable_common_tls_context()->add_alpn_protocols("h2");
} else if (upstream_protocol_ == FakeHttpConnection::Type::HTTP1) {
} else if (upstream_config_.upstream_protocol_ == FakeHttpConnection::Type::HTTP1) {
tls_context.mutable_common_tls_context()->add_alpn_protocols("http/1.1");
}
auto cfg = std::make_unique<Extensions::TransportSockets::Tls::ServerContextConfigImpl>(
Expand All @@ -135,15 +135,12 @@ Network::TransportSocketFactoryPtr BaseIntegrationTest::createUpstreamTlsContext

void BaseIntegrationTest::createUpstreams() {
for (uint32_t i = 0; i < fake_upstreams_count_; ++i) {

auto endpoint = upstream_address_fn_(i);
if (autonomous_upstream_) {
ASSERT(!enable_half_close_);
fake_upstreams_.emplace_back(new AutonomousUpstream(
endpoint, upstream_protocol_, *time_system_, autonomous_allow_incomplete_streams_));
fake_upstreams_.emplace_back(
new AutonomousUpstream(endpoint, upstreamConfig(), autonomous_allow_incomplete_streams_));
} else {
fake_upstreams_.emplace_back(new FakeUpstream(endpoint, upstream_protocol_, *time_system_,
enable_half_close_, udp_fake_upstream_));
fake_upstreams_.emplace_back(new FakeUpstream(endpoint, upstreamConfig()));
}
}
}
Expand Down Expand Up @@ -204,8 +201,8 @@ void BaseIntegrationTest::createEnvoy() {
}

void BaseIntegrationTest::setUpstreamProtocol(FakeHttpConnection::Type protocol) {
upstream_protocol_ = protocol;
if (upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
upstream_config_.upstream_protocol_ = protocol;
if (upstream_config_.upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
config_helper_.addConfigModifier(
[&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
RELEASE_ASSERT(bootstrap.mutable_static_resources()->clusters_size() >= 1, "");
Expand Down
49 changes: 27 additions & 22 deletions test/integration/base_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
void setDeterministic() { deterministic_ = true; }
void setNewCodecs() { config_helper_.setNewCodecs(); }

FakeHttpConnection::Type upstreamProtocol() const { return upstream_protocol_; }
FakeHttpConnection::Type upstreamProtocol() const { return upstream_config_.upstream_protocol_; }

IntegrationTcpClientPtr
makeTcpConnection(uint32_t port,
Expand Down Expand Up @@ -322,26 +322,30 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
// Creates a fake upstream bound to the specified unix domain socket path.
std::unique_ptr<FakeUpstream> createFakeUpstream(const std::string& uds_path,
FakeHttpConnection::Type type) {
return std::make_unique<FakeUpstream>(uds_path, type, timeSystem());
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
return std::make_unique<FakeUpstream>(uds_path, config);
}
// Creates a fake upstream bound to the specified |address|.
std::unique_ptr<FakeUpstream>
createFakeUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, bool enable_half_close = false,
bool udp_fake_upstream = false) {
return std::make_unique<FakeUpstream>(address, type, timeSystem(), enable_half_close,
udp_fake_upstream);
FakeHttpConnection::Type type) {
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
return std::make_unique<FakeUpstream>(address, config);
}
// Creates a fake upstream bound to INADDR_ANY and there is no specified port.
std::unique_ptr<FakeUpstream> createFakeUpstream(FakeHttpConnection::Type type,
bool enable_half_close = false) {
return std::make_unique<FakeUpstream>(0, type, version_, timeSystem(), enable_half_close);
std::unique_ptr<FakeUpstream> createFakeUpstream(FakeHttpConnection::Type type) {
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
return std::make_unique<FakeUpstream>(0, version_, config);
}
std::unique_ptr<FakeUpstream>
createFakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
FakeHttpConnection::Type type) {
return std::make_unique<FakeUpstream>(std::move(transport_socket_factory), 0, type, version_,
timeSystem());
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
return std::make_unique<FakeUpstream>(std::move(transport_socket_factory), 0, version_, config);
}
// Helper to add FakeUpstream.
// Add a fake upstream bound to the specified unix domain socket path.
Expand All @@ -350,22 +354,26 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
}
// Add a fake upstream bound to the specified |address|.
void addFakeUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, bool enable_half_close = false,
bool udp_fake_upstream = false) {
fake_upstreams_.emplace_back(
createFakeUpstream(address, type, enable_half_close, udp_fake_upstream));
FakeHttpConnection::Type type) {
fake_upstreams_.emplace_back(createFakeUpstream(address, type));
}
// Add a fake upstream bound to INADDR_ANY and there is no specified port.
void addFakeUpstream(FakeHttpConnection::Type type, bool enable_half_close = false) {
fake_upstreams_.emplace_back(createFakeUpstream(type, enable_half_close));
void addFakeUpstream(FakeHttpConnection::Type type) {
fake_upstreams_.emplace_back(createFakeUpstream(type));
}
void addFakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
FakeHttpConnection::Type type) {
fake_upstreams_.emplace_back(createFakeUpstream(std::move(transport_socket_factory), type));
}

protected:
void setUdpFakeUpstream(bool value) { upstream_config_.udp_fake_upstream_ = value; }
bool initialized() const { return initialized_; }
const FakeUpstreamConfig& upstreamConfig() {
// TODO(alyssawilk) make enable_half_close_ private and remove this.
upstream_config_.enable_half_close_ = enable_half_close_;
return upstream_config_;
}

std::unique_ptr<Stats::Scope> upstream_stats_store_;

Expand Down Expand Up @@ -436,9 +444,6 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {

bool enable_half_close_{false};

// Whether the default created fake upstreams are UDP listeners.
bool udp_fake_upstream_{false};

// True if test will use a fixed RNG value.
bool deterministic_{};

Expand All @@ -454,8 +459,8 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
bool v2_bootstrap_{false};

private:
// The type for the Envoy-to-backend connection
FakeHttpConnection::Type upstream_protocol_{FakeHttpConnection::Type::HTTP1};
// Configuration for the fake upstream.
FakeUpstreamConfig upstream_config_{time_system_};
// True if initialized() has been called.
bool initialized_{};
};
Expand Down
41 changes: 20 additions & 21 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,11 @@ AssertionResult FakeHttpConnection::waitForNewStream(Event::Dispatcher& client_d
return AssertionSuccess();
}

FakeUpstream::FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type,
Event::TestTimeSystem& time_system)
FakeUpstream::FakeUpstream(const std::string& uds_path, const FakeUpstreamConfig& config)
: FakeUpstream(Network::Test::createRawBufferSocketFactory(),
Network::SocketPtr{new Network::UdsListenSocket(
std::make_shared<Network::Address::PipeInstance>(uds_path))},
type, time_system, false) {
config) {
ENVOY_LOG(info, "starting fake server on unix domain socket {}", uds_path);
}

Expand All @@ -411,43 +410,43 @@ makeUdpListenSocket(const Network::Address::InstanceConstSharedPtr& address) {
}

FakeUpstream::FakeUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, Event::TestTimeSystem& time_system,
bool enable_half_close, bool udp_fake_upstream)
const FakeUpstreamConfig& config)
: FakeUpstream(Network::Test::createRawBufferSocketFactory(),
udp_fake_upstream ? makeUdpListenSocket(address) : makeTcpListenSocket(address),
type, time_system, enable_half_close) {
config.udp_fake_upstream_ ? makeUdpListenSocket(address)
: makeTcpListenSocket(address),
config) {
ENVOY_LOG(info, "starting fake server on socket {}:{}. Address version is {}. UDP={}",
address->ip()->addressAsString(), address->ip()->port(),
Network::Test::addressVersionAsString(address->ip()->version()), udp_fake_upstream);
Network::Test::addressVersionAsString(address->ip()->version()),
config.udp_fake_upstream_);
}

FakeUpstream::FakeUpstream(uint32_t port, FakeHttpConnection::Type type,
Network::Address::IpVersion version, Event::TestTimeSystem& time_system,
bool enable_half_close)
FakeUpstream::FakeUpstream(uint32_t port, Network::Address::IpVersion version,
const FakeUpstreamConfig& config)
: FakeUpstream(Network::Test::createRawBufferSocketFactory(),
makeTcpListenSocket(port, version), type, time_system, enable_half_close) {
makeTcpListenSocket(port, version), config) {
ENVOY_LOG(info, "starting fake server on port {}. Address version is {}",
localAddress()->ip()->port(), Network::Test::addressVersionAsString(version));
}

FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
uint32_t port, FakeHttpConnection::Type type,
Network::Address::IpVersion version, Event::TestTimeSystem& time_system)
: FakeUpstream(std::move(transport_socket_factory), makeTcpListenSocket(port, version), type,
time_system, false) {
uint32_t port, Network::Address::IpVersion version,
const FakeUpstreamConfig& config)
: FakeUpstream(std::move(transport_socket_factory), makeTcpListenSocket(port, version),
config) {
ENVOY_LOG(info, "starting fake SSL server on port {}. Address version is {}",
localAddress()->ip()->port(), Network::Test::addressVersionAsString(version));
}

FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
Network::SocketPtr&& listen_socket, FakeHttpConnection::Type type,
Event::TestTimeSystem& time_system, bool enable_half_close)
: http_type_(type), socket_(Network::SocketSharedPtr(listen_socket.release())),
Network::SocketPtr&& listen_socket, const FakeUpstreamConfig& config)
: http_type_(config.upstream_protocol_),
socket_(Network::SocketSharedPtr(listen_socket.release())),
socket_factory_(std::make_shared<FakeListenSocketFactory>(socket_)),
api_(Api::createApiForTest(stats_store_)), time_system_(time_system),
api_(Api::createApiForTest(stats_store_)), time_system_(config.time_system_),
dispatcher_(api_->allocateDispatcher("fake_upstream")),
handler_(new Server::ConnectionHandlerImpl(*dispatcher_, 0)),
read_disable_on_new_connection_(true), enable_half_close_(enable_half_close),
read_disable_on_new_connection_(true), enable_half_close_(config.enable_half_close_),
listener_(*this),
filter_chain_(Network::Test::createEmptyFilterChain(std::move(transport_socket_factory))) {
thread_ = api_->threadFactory().createThread([this]() -> void { threadRoutine(); });
Expand Down
27 changes: 17 additions & 10 deletions test/integration/fake_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ class FakeRawConnection : public FakeConnectionBase {

using FakeRawConnectionPtr = std::unique_ptr<FakeRawConnection>;

struct FakeUpstreamConfig {
FakeUpstreamConfig(Event::TestTimeSystem& time_system) : time_system_(time_system) {}

Event::TestTimeSystem& time_system_;
FakeHttpConnection::Type upstream_protocol_{FakeHttpConnection::Type::HTTP1};
bool enable_half_close_{};
bool udp_fake_upstream_{};
};

/**
* Provides a fake upstream server for integration testing.
*/
Expand All @@ -535,19 +544,18 @@ class FakeUpstream : Logger::Loggable<Logger::Id::testing>,
public Network::FilterChainFactory {
public:
// Creates a fake upstream bound to the specified unix domain socket path.
FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type,
Event::TestTimeSystem& time_system);
FakeUpstream(const std::string& uds_path, const FakeUpstreamConfig& config);

// Creates a fake upstream bound to the specified |address|.
FakeUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, Event::TestTimeSystem& time_system,
bool enable_half_close = false, bool udp_fake_upstream = false);
const FakeUpstreamConfig& config);

// Creates a fake upstream bound to INADDR_ANY and the specified |port|.
FakeUpstream(uint32_t port, FakeHttpConnection::Type type, Network::Address::IpVersion version,
Event::TestTimeSystem& time_system, bool enable_half_close = false);
FakeUpstream(uint32_t port, Network::Address::IpVersion version,
const FakeUpstreamConfig& config);

FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, uint32_t port,
FakeHttpConnection::Type type, Network::Address::IpVersion version,
Event::TestTimeSystem& time_system);
Network::Address::IpVersion version, const FakeUpstreamConfig& config);
~FakeUpstream() override;

FakeHttpConnection::Type httpType() { return http_type_; }
Expand Down Expand Up @@ -626,8 +634,7 @@ class FakeUpstream : Logger::Loggable<Logger::Id::testing>,

private:
FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
Network::SocketPtr&& connection, FakeHttpConnection::Type type,
Event::TestTimeSystem& time_system, bool enable_half_close);
Network::SocketPtr&& connection, const FakeUpstreamConfig& config);

class FakeListenSocketFactory : public Network::ListenSocketFactory {
public:
Expand Down
Loading