/proc/self/cwd/test/common/grpc/grpc_client_integration.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/config/core/v3/grpc_service.pb.h" |
4 | | |
5 | | #include "source/common/common/assert.h" |
6 | | |
7 | | #include "test/test_common/environment.h" |
8 | | #include "test/test_common/utility.h" |
9 | | |
10 | | #include "gtest/gtest.h" |
11 | | |
12 | | namespace Envoy { |
13 | | namespace Grpc { |
14 | | |
15 | | // Support parameterizing over state-of-the-world xDS vs delta xDS. |
16 | | enum class SotwOrDelta { Sotw, Delta, UnifiedSotw, UnifiedDelta }; |
17 | | |
18 | | // Unified or Legacy grpc mux implementation |
19 | | enum class LegacyOrUnified { Legacy, Unified }; |
20 | | |
21 | | class BaseGrpcClientIntegrationParamTest { |
22 | | public: |
23 | 591 | virtual ~BaseGrpcClientIntegrationParamTest() = default; |
24 | | virtual Network::Address::IpVersion ipVersion() const PURE; |
25 | | virtual ClientType clientType() const PURE; |
26 | | |
27 | | void setGrpcService(envoy::config::core::v3::GrpcService& grpc_service, |
28 | | const std::string& cluster_name, |
29 | 591 | Network::Address::InstanceConstSharedPtr address) { |
30 | | // Set a 5 minute timeout to avoid flakes. If this causes a real test timeout the test is |
31 | | // broken and/or should be using simulated time. |
32 | 591 | grpc_service.mutable_timeout()->CopyFrom(Protobuf::util::TimeUtil::SecondsToDuration(300)); |
33 | 591 | switch (clientType()) { |
34 | 591 | case ClientType::EnvoyGrpc: |
35 | 591 | grpc_service.mutable_envoy_grpc()->set_cluster_name(cluster_name); |
36 | 591 | break; |
37 | 0 | case ClientType::GoogleGrpc: { |
38 | 0 | auto* google_grpc = grpc_service.mutable_google_grpc(); |
39 | 0 | google_grpc->set_target_uri(address->asString()); |
40 | 0 | google_grpc->set_stat_prefix(cluster_name); |
41 | 0 | break; |
42 | 0 | } |
43 | 0 | default: |
44 | 0 | PANIC("reached unexpected code"); |
45 | 591 | } |
46 | 591 | } |
47 | | }; |
48 | | |
49 | | class GrpcClientIntegrationParamTest |
50 | | : public BaseGrpcClientIntegrationParamTest, |
51 | | public testing::TestWithParam<std::tuple<Network::Address::IpVersion, ClientType>> { |
52 | | public: |
53 | | static std::string protocolTestParamsToString( |
54 | 0 | const ::testing::TestParamInfo<std::tuple<Network::Address::IpVersion, ClientType>>& p) { |
55 | 0 | return fmt::format("{}_{}", TestUtility::ipVersionToString(std::get<0>(p.param)), |
56 | 0 | std::get<1>(p.param) == ClientType::GoogleGrpc ? "GoogleGrpc" : "EnvoyGrpc"); |
57 | 0 | } |
58 | 0 | Network::Address::IpVersion ipVersion() const override { return std::get<0>(GetParam()); } |
59 | 0 | ClientType clientType() const override { return std::get<1>(GetParam()); } |
60 | | }; |
61 | | |
62 | | // TODO(kbaichoo): Revert to using GrpcClientIntegrationParamTest for all |
63 | | // derived classes when deferred processing is enabled by default. It's |
64 | | // parameterized by deferred processing now to avoid bit rot since the feature |
65 | | // is off by default. |
66 | | class GrpcClientIntegrationParamTestWithDeferredProcessing |
67 | | : public Grpc::BaseGrpcClientIntegrationParamTest, |
68 | | public testing::TestWithParam< |
69 | | std::tuple<std::tuple<Network::Address::IpVersion, Grpc::ClientType>, bool>> { |
70 | | public: |
71 | | static std::string protocolTestParamsToString( |
72 | | const ::testing::TestParamInfo< |
73 | 0 | std::tuple<std::tuple<Network::Address::IpVersion, Grpc::ClientType>, bool>>& p) { |
74 | 0 | return fmt::format( |
75 | 0 | "{}_{}_{}", TestUtility::ipVersionToString(std::get<0>(std::get<0>(p.param))), |
76 | 0 | std::get<1>(std::get<0>(p.param)) == Grpc::ClientType::GoogleGrpc ? "GoogleGrpc" |
77 | 0 | : "EnvoyGrpc", |
78 | 0 | std::get<1>(p.param) ? "WithDeferredProcessing" : "NoDeferredProcessing"); |
79 | 0 | } |
80 | 0 | Network::Address::IpVersion ipVersion() const override { |
81 | 0 | return std::get<0>(std::get<0>(GetParam())); |
82 | 0 | } |
83 | 0 | Grpc::ClientType clientType() const override { return std::get<1>(std::get<0>(GetParam())); } |
84 | 0 | bool deferredProcessing() const { return std::get<1>(GetParam()); } |
85 | | }; |
86 | | |
87 | | class UnifiedOrLegacyMuxIntegrationParamTest |
88 | | : public BaseGrpcClientIntegrationParamTest, |
89 | | public testing::TestWithParam< |
90 | | std::tuple<Network::Address::IpVersion, ClientType, LegacyOrUnified>> { |
91 | | public: |
92 | | ~UnifiedOrLegacyMuxIntegrationParamTest() override = default; |
93 | | static std::string protocolTestParamsToString( |
94 | | const ::testing::TestParamInfo< |
95 | 0 | std::tuple<Network::Address::IpVersion, ClientType, LegacyOrUnified>>& p) { |
96 | 0 | return fmt::format("{}_{}_{}", TestUtility::ipVersionToString(std::get<0>(p.param)), |
97 | 0 | std::get<1>(p.param) == ClientType::GoogleGrpc ? "GoogleGrpc" : "EnvoyGrpc", |
98 | 0 | std::get<2>(p.param) == LegacyOrUnified::Legacy ? "Legacy" : "Unified"); |
99 | 0 | } |
100 | 0 | Network::Address::IpVersion ipVersion() const override { return std::get<0>(GetParam()); } |
101 | 0 | ClientType clientType() const override { return std::get<1>(GetParam()); } |
102 | 0 | LegacyOrUnified unifiedOrLegacy() const { return std::get<2>(GetParam()); } |
103 | 0 | bool isUnified() const { return std::get<2>(GetParam()) == LegacyOrUnified::Unified; } |
104 | | }; |
105 | | |
106 | | class DeltaSotwIntegrationParamTest |
107 | | : public BaseGrpcClientIntegrationParamTest, |
108 | | public testing::TestWithParam< |
109 | | std::tuple<Network::Address::IpVersion, ClientType, SotwOrDelta>> { |
110 | | public: |
111 | | ~DeltaSotwIntegrationParamTest() override = default; |
112 | | static std::string |
113 | | protocolTestParamsToString(const ::testing::TestParamInfo< |
114 | 0 | std::tuple<Network::Address::IpVersion, ClientType, SotwOrDelta>>& p) { |
115 | 0 | return fmt::format("{}_{}_{}", TestUtility::ipVersionToString(std::get<0>(p.param)), |
116 | 0 | std::get<1>(p.param) == ClientType::GoogleGrpc ? "GoogleGrpc" : "EnvoyGrpc", |
117 | 0 | std::get<2>(p.param) == SotwOrDelta::Delta ? "Delta" : "StateOfTheWorld"); |
118 | 0 | } |
119 | 0 | Network::Address::IpVersion ipVersion() const override { return std::get<0>(GetParam()); } |
120 | 0 | ClientType clientType() const override { return std::get<1>(GetParam()); } |
121 | 0 | SotwOrDelta sotwOrDelta() const { return std::get<2>(GetParam()); } |
122 | | }; |
123 | | |
124 | | class DeltaSotwDeferredClustersIntegrationParamTest |
125 | | : public BaseGrpcClientIntegrationParamTest, |
126 | | public testing::TestWithParam< |
127 | | std::tuple<Network::Address::IpVersion, ClientType, SotwOrDelta, bool>> { |
128 | | public: |
129 | | ~DeltaSotwDeferredClustersIntegrationParamTest() override = default; |
130 | | static std::string protocolTestParamsToString( |
131 | | const ::testing::TestParamInfo< |
132 | 0 | std::tuple<Network::Address::IpVersion, ClientType, SotwOrDelta, bool>>& p) { |
133 | 0 | return fmt::format("{}_{}_{}_{}", TestUtility::ipVersionToString(std::get<0>(p.param)), |
134 | 0 | std::get<1>(p.param) == ClientType::GoogleGrpc ? "GoogleGrpc" : "EnvoyGrpc", |
135 | 0 | std::get<2>(p.param) == SotwOrDelta::Delta ? "Delta" : "StateOfTheWorld", |
136 | 0 | std::get<3>(p.param) == true ? "DeferredClusters" : ""); |
137 | 0 | } |
138 | 0 | Network::Address::IpVersion ipVersion() const override { return std::get<0>(GetParam()); } |
139 | 0 | ClientType clientType() const override { return std::get<1>(GetParam()); } |
140 | 0 | SotwOrDelta sotwOrDelta() const { return std::get<2>(GetParam()); } |
141 | 0 | bool useDeferredCluster() const { return std::get<3>(GetParam()); } |
142 | | }; |
143 | | |
144 | | // Skip tests based on gRPC client type. |
145 | | #define SKIP_IF_GRPC_CLIENT(client_type) \ |
146 | | if (clientType() == (client_type)) { \ |
147 | | return; \ |
148 | | } |
149 | | |
150 | | // Skip tests based on xDS delta vs state-of-the-world. |
151 | | #define SKIP_IF_XDS_IS(xds) \ |
152 | | if (sotwOrDelta() == (xds)) { \ |
153 | | return; \ |
154 | | } |
155 | | |
156 | | #define GRPC_CLIENT_INTEGRATION_PARAMS \ |
157 | | testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), \ |
158 | | testing::ValuesIn(TestEnvironment::getsGrpcVersionsForTest())) |
159 | | #define GRPC_CLIENT_INTEGRATION_DEFERRED_PROCESSING_PARAMS \ |
160 | | testing::Combine(GRPC_CLIENT_INTEGRATION_PARAMS, testing::Bool()) |
161 | | #define DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS \ |
162 | | testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), \ |
163 | | testing::ValuesIn(TestEnvironment::getsGrpcVersionsForTest()), \ |
164 | | testing::Values(Grpc::SotwOrDelta::Sotw, Grpc::SotwOrDelta::Delta)) |
165 | | #define DELTA_SOTW_GRPC_CLIENT_DEFERRED_CLUSTERS_INTEGRATION_PARAMS \ |
166 | | testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), \ |
167 | | testing::ValuesIn(TestEnvironment::getsGrpcVersionsForTest()), \ |
168 | | testing::Values(Grpc::SotwOrDelta::Sotw, Grpc::SotwOrDelta::Delta), \ |
169 | | testing::Values(true, false)) |
170 | | #define UNIFIED_LEGACY_GRPC_CLIENT_INTEGRATION_PARAMS \ |
171 | | testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), \ |
172 | | testing::ValuesIn(TestEnvironment::getsGrpcVersionsForTest()), \ |
173 | | testing::Values(Grpc::LegacyOrUnified::Legacy, Grpc::LegacyOrUnified::Unified)) |
174 | | #define DELTA_SOTW_UNIFIED_GRPC_CLIENT_INTEGRATION_PARAMS \ |
175 | | testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), \ |
176 | | testing::ValuesIn(TestEnvironment::getsGrpcVersionsForTest()), \ |
177 | | testing::Values(Grpc::SotwOrDelta::Sotw, Grpc::SotwOrDelta::Delta, \ |
178 | | Grpc::SotwOrDelta::UnifiedSotw, \ |
179 | | Grpc::SotwOrDelta::UnifiedDelta)) |
180 | | |
181 | | } // namespace Grpc |
182 | | } // namespace Envoy |