forked from intel/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_protocol_integration.h
133 lines (117 loc) · 5.57 KB
/
http_protocol_integration.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
struct HttpProtocolTestParams {
Network::Address::IpVersion version;
Http::CodecType downstream_protocol;
Http::CodecType upstream_protocol;
Http2Impl http2_implementation;
bool defer_processing_backedup_streams;
};
// Allows easy testing of Envoy code for HTTP/HTTP2 upstream/downstream.
//
// Usage:
//
// using MyTest = HttpProtocolIntegrationTest;
//
// INSTANTIATE_TEST_SUITE_P(Protocols, MyTest,
// testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParams()),
// HttpProtocolIntegrationTest::protocolTestParamsToString);
//
//
// TEST_P(MyTest, TestInstance) {
// ....
// }
// TODO(#20996) consider switching to SimulatedTimeSystem instead of using real time.
class HttpProtocolIntegrationTest : public testing::TestWithParam<HttpProtocolTestParams>,
public HttpIntegrationTest {
public:
// By default returns 8 combinations of
// [HTTP upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP upstream / HTTP2 downstream] x [IPv4, Ipv6]
// [HTTP2 upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP2 upstream / HTTP2 downstream] x [IPv4, Ipv6]
//
// Upstream and downstream protocols may be changed via the input vectors.
// Address combinations are propagated from TestEnvironment::getIpVersionsForTest()
static std::vector<HttpProtocolTestParams> getProtocolTestParams(
const std::vector<Http::CodecType>& downstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2},
const std::vector<Http::CodecType>& upstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2});
// Allows pretty printed test names of the form
// FooTestCase.BarInstance/IPv4_Http2Downstream_HttpUpstream
static std::string
protocolTestParamsToString(const ::testing::TestParamInfo<HttpProtocolTestParams>& p);
HttpProtocolIntegrationTest()
: HttpIntegrationTest(
GetParam().downstream_protocol, GetParam().version,
ConfigHelper::httpProxyConfig(/*downstream_is_quic=*/GetParam().downstream_protocol ==
Http::CodecType::HTTP3)) {
setupHttp2Overrides(GetParam().http2_implementation);
config_helper_.addRuntimeOverride(Runtime::defer_processing_backedup_streams,
GetParam().defer_processing_backedup_streams ? "true"
: "false");
}
void SetUp() override {
setDownstreamProtocol(GetParam().downstream_protocol);
setUpstreamProtocol(GetParam().upstream_protocol);
}
enum class SkipOnStream { Upstream, Downstream, AnyStream };
bool skipForH2Uhv([[maybe_unused]] SkipOnStream stream) {
#ifdef ENVOY_ENABLE_UHV
return GetParam().http2_implementation == Http2Impl::Oghttp2 &&
(stream == SkipOnStream::AnyStream ||
(stream == SkipOnStream::Downstream &&
downstreamProtocol() == Http::CodecType::HTTP2) ||
(stream == SkipOnStream::Upstream && upstreamProtocol() == Http::CodecType::HTTP2));
#endif
return false;
}
};
class UpstreamDownstreamIntegrationTest
: public testing::TestWithParam<std::tuple<HttpProtocolTestParams, bool>>,
public HttpIntegrationTest {
public:
UpstreamDownstreamIntegrationTest()
: HttpIntegrationTest(
std::get<0>(GetParam()).downstream_protocol, std::get<0>(GetParam()).version,
ConfigHelper::httpProxyConfig(std::get<0>(GetParam()).downstream_protocol ==
Http::CodecType::HTTP3)) {
setupHttp2Overrides(std::get<0>(GetParam()).http2_implementation);
config_helper_.addRuntimeOverride(
Runtime::defer_processing_backedup_streams,
std::get<0>(GetParam()).defer_processing_backedup_streams ? "true" : "false");
}
static std::string testParamsToString(
const ::testing::TestParamInfo<std::tuple<HttpProtocolTestParams, bool>>& params) {
return fmt::format(
"{}_{}",
HttpProtocolIntegrationTest::protocolTestParamsToString(
::testing::TestParamInfo<HttpProtocolTestParams>(std::get<0>(params.param), 0)),
std::get<1>(params.param) ? "DownstreamFilter" : "UpstreamFilter");
}
static std::vector<std::tuple<HttpProtocolTestParams, bool>> getDefaultTestParams(
const std::vector<Http::CodecType>& downstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2},
const std::vector<Http::CodecType>& upstream_protocols = {Http::CodecType::HTTP1,
Http::CodecType::HTTP2}) {
std::vector<std::tuple<HttpProtocolTestParams, bool>> ret;
std::vector<HttpProtocolTestParams> protocol_defaults =
HttpProtocolIntegrationTest::getProtocolTestParams(downstream_protocols,
upstream_protocols);
for (auto& param : protocol_defaults) {
ret.push_back(std::make_tuple(param, true));
ret.push_back(std::make_tuple(param, false));
}
return ret;
}
void SetUp() override {
setDownstreamProtocol(std::get<0>(GetParam()).downstream_protocol);
setUpstreamProtocol(std::get<0>(GetParam()).upstream_protocol);
testing_downstream_filter_ = std::get<1>(GetParam());
}
bool testing_downstream_filter_;
};
} // namespace Envoy