forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtds_integration_test.cc
180 lines (160 loc) · 6.15 KB
/
rtds_integration_test.cc
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "envoy/service/runtime/v3/rtds.pb.h"
#include "test/common/grpc/grpc_client_integration.h"
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
namespace {
// TODO(fredlas) set_node_on_first_message_only was true; the delta+SotW unification
// work restores it here.
std::string tdsBootstrapConfig(absl::string_view api_type) {
return fmt::format(R"EOF(
static_resources:
clusters:
- name: dummy_cluster
load_assignment:
cluster_name: dummy_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 0
- name: rtds_cluster
http2_protocol_options: {{}}
load_assignment:
cluster_name: rtds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 0
layered_runtime:
layers:
- name: some_static_layer
static_layer:
foo: whatevs
bar: yar
- name: some_rtds_layer
rtds_layer:
name: some_rtds_layer
rtds_config:
api_config_source:
api_type: {}
grpc_services:
envoy_grpc:
cluster_name: rtds_cluster
set_node_on_first_message_only: false
- name: some_admin_layer
admin_layer: {{}}
admin:
access_log_path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 0
)EOF",
api_type);
}
class RtdsIntegrationTest : public Grpc::DeltaSotwIntegrationParamTest, public HttpIntegrationTest {
public:
RtdsIntegrationTest()
: HttpIntegrationTest(
Http::CodecClient::Type::HTTP2, ipVersion(),
tdsBootstrapConfig(sotwOrDelta() == Grpc::SotwOrDelta::Sotw ? "GRPC" : "DELTA_GRPC")) {
use_lds_ = false;
create_xds_upstream_ = true;
sotw_or_delta_ = sotwOrDelta();
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
// The tests infra expects the xDS server to be the second fake upstream, so
// we need a dummy data plane cluster.
setUpstreamCount(1);
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
// Initial RTDS connection.
createXdsConnection();
AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
// Register admin port.
registerTestServerPorts({});
initial_load_success_ = test_server_->counter("runtime.load_success")->value();
initial_keys_ = test_server_->gauge("runtime.num_keys")->value();
}
void acceptXdsConnection() {
AssertionResult result = // xds_connection_ is filled with the new FakeHttpConnection.
fake_upstreams_[0]->waitForHttpConnection(*dispatcher_, xds_connection_);
RELEASE_ASSERT(result, result.message());
result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
}
std::string getRuntimeKey(const std::string& key) {
auto response = IntegrationUtil::makeSingleRequest(
lookupPort("admin"), "GET", "/runtime?format=json", "", downstreamProtocol(), version_);
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
Json::ObjectSharedPtr loader = TestEnvironment::jsonLoadFromString(response->body());
auto entries = loader->getObject("entries");
if (entries->hasObject(key)) {
return entries->getObject(key)->getString("final_value");
}
return "";
}
uint32_t initial_load_success_{};
uint32_t initial_keys_{};
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDelta, RtdsIntegrationTest,
DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS);
TEST_P(RtdsIntegrationTest, RtdsReload) {
initialize();
EXPECT_EQ("whatevs", getRuntimeKey("foo"));
EXPECT_EQ("yar", getRuntimeKey("bar"));
EXPECT_EQ("", getRuntimeKey("baz"));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Runtime, "", {"some_rtds_layer"},
{"some_rtds_layer"}, {}, true));
auto some_rtds_layer = TestUtility::parseYaml<envoy::service::runtime::v3::Runtime>(R"EOF(
name: some_rtds_layer
layer:
foo: bar
baz: meh
)EOF");
sendDiscoveryResponse<envoy::service::runtime::v3::Runtime>(
Config::TypeUrl::get().Runtime, {some_rtds_layer}, {some_rtds_layer}, {}, "1");
test_server_->waitForCounterGe("runtime.load_success", initial_load_success_ + 1);
EXPECT_EQ("bar", getRuntimeKey("foo"));
EXPECT_EQ("yar", getRuntimeKey("bar"));
EXPECT_EQ("meh", getRuntimeKey("baz"));
EXPECT_EQ(0, test_server_->counter("runtime.load_error")->value());
EXPECT_EQ(initial_load_success_ + 1, test_server_->counter("runtime.load_success")->value());
EXPECT_EQ(initial_keys_ + 1, test_server_->gauge("runtime.num_keys")->value());
EXPECT_EQ(3, test_server_->gauge("runtime.num_layers")->value());
EXPECT_TRUE(
compareDiscoveryRequest(Config::TypeUrl::get().Runtime, "1", {"some_rtds_layer"}, {}, {}));
some_rtds_layer = TestUtility::parseYaml<envoy::service::runtime::v3::Runtime>(R"EOF(
name: some_rtds_layer
layer:
baz: saz
)EOF");
sendDiscoveryResponse<envoy::service::runtime::v3::Runtime>(
Config::TypeUrl::get().Runtime, {some_rtds_layer}, {some_rtds_layer}, {}, "2");
test_server_->waitForCounterGe("runtime.load_success", initial_load_success_ + 2);
EXPECT_EQ("whatevs", getRuntimeKey("foo"));
EXPECT_EQ("yar", getRuntimeKey("bar"));
EXPECT_EQ("saz", getRuntimeKey("baz"));
EXPECT_EQ(0, test_server_->counter("runtime.load_error")->value());
EXPECT_EQ(initial_load_success_ + 2, test_server_->counter("runtime.load_success")->value());
EXPECT_EQ(initial_keys_ + 1, test_server_->gauge("runtime.num_keys")->value());
EXPECT_EQ(3, test_server_->gauge("runtime.num_layers")->value());
}
} // namespace
} // namespace Envoy