-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
ads_integration_test.cc
979 lines (838 loc) · 48.5 KB
/
ads_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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
#include "envoy/admin/v2alpha/config_dump.pb.h"
#include "envoy/api/v2/cds.pb.h"
#include "envoy/api/v2/discovery.pb.h"
#include "envoy/api/v2/eds.pb.h"
#include "envoy/api/v2/lds.pb.h"
#include "envoy/api/v2/rds.pb.h"
#include "envoy/api/v2/route/route.pb.h"
#include "envoy/grpc/status.h"
#include "envoy/service/discovery/v2/ads.pb.h"
#include "envoy/stats/scope.h"
#include "common/config/protobuf_link_hacks.h"
#include "common/config/resources.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"
#include "test/common/grpc/grpc_client_integration.h"
#include "test/integration/http_integration.h"
#include "test/integration/utility.h"
#include "test/mocks/server/mocks.h"
#include "test/test_common/network_utility.h"
#include "test/test_common/simulated_time_system.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
using testing::AssertionFailure;
using testing::AssertionResult;
using testing::AssertionSuccess;
using testing::IsSubstring;
namespace Envoy {
namespace {
const std::string config = R"EOF(
dynamic_resources:
lds_config: {ads: {}}
cds_config: {ads: {}}
ads_config:
api_type: GRPC
static_resources:
clusters:
name: dummy_cluster
connect_timeout: { seconds: 5 }
type: STATIC
hosts:
socket_address:
address: 127.0.0.1
port_value: 0
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
admin:
access_log_path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 0
)EOF";
class AdsIntegrationTest : public Grpc::GrpcClientIntegrationParamTest, public HttpIntegrationTest {
public:
AdsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(), config) {
use_lds_ = false;
create_xds_upstream_ = true;
tls_xds_upstream_ = true;
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
envoy::api::v2::Cluster buildCluster(const std::string& name) {
return TestUtility::parseYaml<envoy::api::v2::Cluster>(fmt::format(R"EOF(
name: {}
connect_timeout: 5s
type: EDS
eds_cluster_config: {{ eds_config: {{ ads: {{}} }} }}
lb_policy: ROUND_ROBIN
http2_protocol_options: {{}}
)EOF",
name));
}
envoy::api::v2::ClusterLoadAssignment buildClusterLoadAssignment(const std::string& name) {
return TestUtility::parseYaml<envoy::api::v2::ClusterLoadAssignment>(
fmt::format(R"EOF(
cluster_name: {}
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {}
port_value: {}
)EOF",
name, Network::Test::getLoopbackAddressString(ipVersion()),
fake_upstreams_[0]->localAddress()->ip()->port()));
}
envoy::api::v2::Listener buildListener(const std::string& name, const std::string& route_config,
const std::string& stat_prefix = "ads_test") {
return TestUtility::parseYaml<envoy::api::v2::Listener>(fmt::format(
R"EOF(
name: {}
address:
socket_address:
address: {}
port_value: 0
filter_chains:
filters:
- name: envoy.http_connection_manager
config:
stat_prefix: {}
codec_type: HTTP2
rds:
route_config_name: {}
config_source: {{ ads: {{}} }}
http_filters: [{{ name: envoy.router }}]
)EOF",
name, Network::Test::getLoopbackAddressString(ipVersion()), stat_prefix, route_config));
}
envoy::api::v2::RouteConfiguration buildRouteConfig(const std::string& name,
const std::string& cluster) {
return TestUtility::parseYaml<envoy::api::v2::RouteConfiguration>(fmt::format(R"EOF(
name: {}
virtual_hosts:
- name: integration
domains: ["*"]
routes:
- match: {{ prefix: "/" }}
route: {{ cluster: {} }}
)EOF",
name, cluster));
}
void makeSingleRequest() {
registerTestServerPorts({"http"});
testRouterHeaderOnlyRequestAndResponse();
cleanupUpstreamAndDownstream();
}
void initialize() override { initializeAds(false); }
void initializeAds(const bool rate_limiting) {
config_helper_.addConfigModifier(
[this, &rate_limiting](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
auto* ads_config = bootstrap.mutable_dynamic_resources()->mutable_ads_config();
if (rate_limiting) {
ads_config->mutable_rate_limit_settings();
}
auto* grpc_service = ads_config->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]);
ads_cluster->set_name("ads_cluster");
auto* context = ads_cluster->mutable_tls_context();
auto* validation_context =
context->mutable_common_tls_context()->mutable_validation_context();
validation_context->mutable_trusted_ca()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamcacert.pem"));
validation_context->add_verify_subject_alt_name("foo.lyft.com");
if (clientType() == Grpc::ClientType::GoogleGrpc) {
auto* google_grpc = grpc_service->mutable_google_grpc();
auto* ssl_creds = google_grpc->mutable_channel_credentials()->mutable_ssl_credentials();
ssl_creds->mutable_root_certs()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamcacert.pem"));
}
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
if (xds_stream_ == nullptr) {
createXdsConnection();
AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
}
}
void testBasicFlow() {
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration,
{buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
const ProtobufWkt::Timestamp first_active_listener_ts_1 =
getListenersConfigDump().dynamic_active_listeners()[0].last_updated();
const ProtobufWkt::Timestamp first_active_cluster_ts_1 =
getClustersConfigDump().dynamic_active_clusters()[0].last_updated();
const ProtobufWkt::Timestamp first_route_config_ts_1 =
getRoutesConfigDump().dynamic_route_configs()[0].last_updated();
// Upgrade RDS/CDS/EDS to a newer config, validate we can process a request.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("cluster_1"), buildCluster("cluster_2")},
{buildCluster("cluster_1"), buildCluster("cluster_2")}, {"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("cluster_1"), buildClusterLoadAssignment("cluster_2")},
{buildClusterLoadAssignment("cluster_1"), buildClusterLoadAssignment("cluster_2")},
{"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_2", "cluster_1"}, {"cluster_2", "cluster_1"},
{"cluster_0"}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "2", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "2",
{"cluster_2", "cluster_1"}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration,
{buildRouteConfig("route_config_0", "cluster_1")},
{buildRouteConfig("route_config_0", "cluster_1")}, {}, "2");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "2",
{"route_config_0"}, {}, {}));
makeSingleRequest();
const ProtobufWkt::Timestamp first_active_listener_ts_2 =
getListenersConfigDump().dynamic_active_listeners()[0].last_updated();
const ProtobufWkt::Timestamp first_active_cluster_ts_2 =
getClustersConfigDump().dynamic_active_clusters()[0].last_updated();
const ProtobufWkt::Timestamp first_route_config_ts_2 =
getRoutesConfigDump().dynamic_route_configs()[0].last_updated();
// Upgrade LDS/RDS, validate we can process a request.
sendDiscoveryResponse<envoy::api::v2::Listener>(Config::TypeUrl::get().Listener,
{buildListener("listener_1", "route_config_1"),
buildListener("listener_2", "route_config_2")},
{buildListener("listener_1", "route_config_1"),
buildListener("listener_2", "route_config_2")},
{"listener_0"}, "2");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "2",
{"route_config_2", "route_config_1", "route_config_0"},
{"route_config_2", "route_config_1"}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "2", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "2",
{"route_config_2", "route_config_1"}, {},
{"route_config_0"}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration,
{buildRouteConfig("route_config_1", "cluster_1"),
buildRouteConfig("route_config_2", "cluster_1")},
{buildRouteConfig("route_config_1", "cluster_1"),
buildRouteConfig("route_config_2", "cluster_1")},
{"route_config_0"}, "3");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "3",
{"route_config_2", "route_config_1"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
makeSingleRequest();
const ProtobufWkt::Timestamp first_active_listener_ts_3 =
getListenersConfigDump().dynamic_active_listeners()[0].last_updated();
const ProtobufWkt::Timestamp first_active_cluster_ts_3 =
getClustersConfigDump().dynamic_active_clusters()[0].last_updated();
const ProtobufWkt::Timestamp first_route_config_ts_3 =
getRoutesConfigDump().dynamic_route_configs()[0].last_updated();
// Expect last_updated timestamps to be updated in a predictable way
// For the listener configs in this example, 1 == 2 < 3.
EXPECT_EQ(first_active_listener_ts_2, first_active_listener_ts_1);
EXPECT_GT(first_active_listener_ts_3, first_active_listener_ts_2);
// For the cluster configs in this example, 1 < 2 == 3.
EXPECT_GT(first_active_cluster_ts_2, first_active_cluster_ts_1);
EXPECT_EQ(first_active_cluster_ts_3, first_active_cluster_ts_2);
// For the route configs in this example, 1 < 2 < 3.
EXPECT_GT(first_route_config_ts_2, first_route_config_ts_1);
EXPECT_GT(first_route_config_ts_3, first_route_config_ts_2);
}
envoy::admin::v2alpha::ClustersConfigDump getClustersConfigDump() {
auto message_ptr =
test_server_->server().admin().getConfigTracker().getCallbacksMap().at("clusters")();
return dynamic_cast<const envoy::admin::v2alpha::ClustersConfigDump&>(*message_ptr);
}
envoy::admin::v2alpha::ListenersConfigDump getListenersConfigDump() {
auto message_ptr =
test_server_->server().admin().getConfigTracker().getCallbacksMap().at("listeners")();
return dynamic_cast<const envoy::admin::v2alpha::ListenersConfigDump&>(*message_ptr);
}
envoy::admin::v2alpha::RoutesConfigDump getRoutesConfigDump() {
auto message_ptr =
test_server_->server().admin().getConfigTracker().getCallbacksMap().at("routes")();
return dynamic_cast<const envoy::admin::v2alpha::RoutesConfigDump&>(*message_ptr);
}
Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{timeSystem()};
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, AdsIntegrationTest, GRPC_CLIENT_INTEGRATION_PARAMS);
// Validate basic config delivery and upgrade.
TEST_P(AdsIntegrationTest, Basic) {
initialize();
testBasicFlow();
}
// Validate basic config delivery and upgrade with RateLimiting.
TEST_P(AdsIntegrationTest, BasicWithRateLimiting) {
initializeAds(true);
testBasicFlow();
}
// Validate that we can recover from failures.
TEST_P(AdsIntegrationTest, Failure) {
initialize();
// Send initial configuration, failing each xDS once (via a type mismatch), validate we can
// process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().Cluster, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(
Config::TypeUrl::get().Cluster, "", {}, {}, {}, Grpc::Status::GrpcStatus::Internal,
fmt::format("{} does not match {}", Config::TypeUrl::get().ClusterLoadAssignment,
Config::TypeUrl::get().Cluster)));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().ClusterLoadAssignment,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(
compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "", {"cluster_0"}, {},
{}, Grpc::Status::GrpcStatus::Internal,
fmt::format("{} does not match {}", Config::TypeUrl::get().Cluster,
Config::TypeUrl::get().ClusterLoadAssignment)));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().Listener, {buildRouteConfig("listener_0", "route_config_0")},
{buildRouteConfig("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(
Config::TypeUrl::get().Listener, "", {}, {}, {}, Grpc::Status::GrpcStatus::Internal,
fmt::format("{} does not match {}", Config::TypeUrl::get().RouteConfiguration,
Config::TypeUrl::get().Listener)));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().RouteConfiguration, {buildListener("route_config_0", "cluster_0")},
{buildListener("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(
compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "", {"route_config_0"}, {},
{}, Grpc::Status::GrpcStatus::Internal,
fmt::format("{} does not match {}", Config::TypeUrl::get().Listener,
Config::TypeUrl::get().RouteConfiguration)));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
}
// Validate that the request with duplicate listeners is rejected.
TEST_P(AdsIntegrationTest, DuplicateWarmingListeners) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
// Send duplicate listeners and validate that the update is rejected.
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener,
{buildListener("duplicae_listener", "route_config_0"),
buildListener("duplicae_listener", "route_config_0")},
{buildListener("duplicae_listener", "route_config_0"),
buildListener("duplicae_listener", "route_config_0")},
{}, "1");
test_server_->waitForCounterGe("listener_manager.lds.update_rejected", 1);
}
// Regression test for the use-after-free crash when processing RDS update (#3953).
TEST_P(AdsIntegrationTest, RdsAfterLdsWithNoRdsChanges) {
initialize();
// Send initial configuration.
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// Validate that we can process a request.
makeSingleRequest();
// Update existing LDS (change stat_prefix).
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0", "rds_crash")},
{buildListener("listener_0", "route_config_0", "rds_crash")}, {}, "2");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
// Update existing RDS (no changes).
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "2");
// Validate that we can process a request again
makeSingleRequest();
}
// Validate that the request with duplicate clusters in the initial request during server init is
// rejected.
TEST_P(AdsIntegrationTest, DuplicateInitialClusters) {
initialize();
// Send initial configuration, failing each xDS once (via a type mismatch), validate we can
// process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster,
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")},
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")}, {}, "1");
test_server_->waitForCounterGe("cluster_manager.cds.update_rejected", 1);
}
// Validate that the request with duplicate clusters in the subsequent requests (warming clusters)
// is rejected.
TEST_P(AdsIntegrationTest, DuplicateWarmingClusters) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {"cluster_0"}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
// Send duplicate warming clusters and validate that the update is rejected.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster,
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")},
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")}, {}, "2");
test_server_->waitForCounterGe("cluster_manager.cds.update_rejected", 1);
}
// Verify CDS is paused during cluster warming.
TEST_P(AdsIntegrationTest, CdsPausedDuringWarming) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
EXPECT_FALSE(
test_server_->server().clusterManager().adsMux().paused(Config::TypeUrl::get().Cluster));
// Send the first warming cluster.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_1")},
{buildCluster("warming_cluster_1")}, {"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
EXPECT_TRUE(
test_server_->server().clusterManager().adsMux().paused(Config::TypeUrl::get().Cluster));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_1"}, {"warming_cluster_1"}, {"cluster_0"}));
// Send the second warming cluster.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_2")},
{buildCluster("warming_cluster_2")}, {"warming_cluster_1"}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
// We would've got a Cluster discovery request with version 2 here, had the CDS not been paused.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_2", "warming_cluster_1"},
{"warming_cluster_2"}, {}));
EXPECT_TRUE(
test_server_->server().clusterManager().adsMux().paused(Config::TypeUrl::get().Cluster));
// Finish warming the clusters.
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_1"),
buildClusterLoadAssignment("warming_cluster_2")},
{buildClusterLoadAssignment("warming_cluster_1"),
buildClusterLoadAssignment("warming_cluster_2")},
{"cluster_0"}, "2");
// Validate that clusters are warmed.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
EXPECT_FALSE(
test_server_->server().clusterManager().adsMux().paused(Config::TypeUrl::get().Cluster));
// CDS is resumed and EDS response was acknowledged.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "3", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "2",
{"warming_cluster_2", "warming_cluster_1"}, {}, {}));
}
// Verify cluster warming is finished only on named EDS response.
TEST_P(AdsIntegrationTest, ClusterWarmingOnNamedResponse) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
// Send the first warming cluster.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_1")},
{buildCluster("warming_cluster_1")}, {"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_1"}, {"warming_cluster_1"}, {"cluster_0"}));
// Send the second warming cluster.
sendDiscoveryResponse<envoy::api::v2::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_2")},
{buildCluster("warming_cluster_2")}, {"warming_cluster_1"}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_2", "warming_cluster_1"},
{"warming_cluster_2"}, {}));
// Finish warming the first cluster.
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_1")},
{buildClusterLoadAssignment("warming_cluster_1")}, {"cluster_0"}, "2");
// Envoy will not finish warming of the second cluster because of the missing load assignments
// i,e. no named EDS response.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
// Finish warming the second cluster.
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_2")},
{buildClusterLoadAssignment("warming_cluster_2")}, {"warming_cluster_1"}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
}
// Regression test for the use-after-free crash when processing RDS update (#3953).
TEST_P(AdsIntegrationTest, RdsAfterLdsWithRdsChange) {
initialize();
// Send initial configuration.
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// Validate that we can process a request.
makeSingleRequest();
// Update existing LDS (change stat_prefix).
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_1")},
{buildCluster("cluster_1")}, {"cluster_0"}, "2");
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_1")},
{buildClusterLoadAssignment("cluster_1")}, {"cluster_0"}, "2");
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0", "rds_crash")},
{buildListener("listener_0", "route_config_0", "rds_crash")}, {}, "2");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
// Update existing RDS (migrate traffic to cluster_1).
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_1")},
{buildRouteConfig("route_config_0", "cluster_1")}, {}, "2");
// Validate that we can process a request after RDS update
test_server_->waitForCounterGe("http.ads_test.rds.route_config_0.config_reload", 2);
makeSingleRequest();
}
// Regression test for the use-after-free crash when a listener awaiting an RDS update is destroyed
// (#6116).
TEST_P(AdsIntegrationTest, RdsAfterLdsInvalidated) {
initialize();
// STEP 1: Initial setup
// ---------------------
// Initial request for any cluster, respond with cluster_0 version 1
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
// Initial request for load assignment for cluster_0, respond with version 1
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
// Request for updates to cluster_0 version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
// Initial request for any listener, respond with listener_0 version 1
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
// Request for updates to load assignment version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
// Initial request for route_config_0 (referenced by listener_0), respond with version 1
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
// Wait for initial listener to be created successfully. Any subsequent listeners will then use
// the dynamic InitManager (see ListenerImpl::initManager).
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// STEP 2: Listener with dynamic InitManager
// -----------------------------------------
// Request for updates to listener_0 version 1, respond with version 2. Under the hood, this
// registers RdsRouteConfigSubscription's init target with the new ListenerImpl instance.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_1")},
{buildListener("listener_0", "route_config_1")}, {}, "2");
// Request for updates to route_config_0 version 1, and initial request for route_config_1
// (referenced by listener_0), don't respond yet!
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_1", "route_config_0"}, {"route_config_1"},
{}));
// STEP 3: "New listener, who dis?"
// --------------------------------
// Request for updates to listener_0 version 2, respond with version 3 (updated stats prefix).
// This should blow away the previous ListenerImpl instance, which is still waiting for
// route_config_1...
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "2", {}, {}, {}));
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_1", "omg")},
{buildListener("listener_0", "route_config_1", "omg")}, {}, "3");
// Respond to prior request for route_config_1. Under the hood, this invokes
// RdsRouteConfigSubscription::runInitializeCallbackIfAny, which references the defunct
// ListenerImpl instance. We should not crash in this event!
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_1", "cluster_0")},
{buildRouteConfig("route_config_1", "cluster_0")}, {"route_config_0"}, "1");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
}
class AdsFailIntegrationTest : public Grpc::GrpcClientIntegrationParamTest,
public HttpIntegrationTest {
public:
AdsFailIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(), config) {
create_xds_upstream_ = true;
use_lds_ = false;
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
auto* grpc_service =
bootstrap.mutable_dynamic_resources()->mutable_ads_config()->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]);
ads_cluster->set_name("ads_cluster");
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
}
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, AdsFailIntegrationTest,
GRPC_CLIENT_INTEGRATION_PARAMS);
// Validate that we don't crash on failed ADS stream.
TEST_P(AdsFailIntegrationTest, ConnectDisconnect) {
initialize();
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
xds_stream_->finishGrpcStream(Grpc::Status::Internal);
}
class AdsConfigIntegrationTest : public Grpc::GrpcClientIntegrationParamTest,
public HttpIntegrationTest {
public:
AdsConfigIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(), config) {
create_xds_upstream_ = true;
use_lds_ = false;
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
auto* grpc_service =
bootstrap.mutable_dynamic_resources()->mutable_ads_config()->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]);
ads_cluster->set_name("ads_cluster");
// Add EDS static Cluster that uses ADS as config Source.
auto* ads_eds_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_eds_cluster->set_name("ads_eds_cluster");
ads_eds_cluster->set_type(envoy::api::v2::Cluster::EDS);
auto* eds_cluster_config = ads_eds_cluster->mutable_eds_cluster_config();
auto* eds_config = eds_cluster_config->mutable_eds_config();
eds_config->mutable_ads();
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
}
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, AdsConfigIntegrationTest,
GRPC_CLIENT_INTEGRATION_PARAMS);
// This is s regression validating that we don't crash on EDS static Cluster that uses ADS.
TEST_P(AdsConfigIntegrationTest, EdsClusterWithAdsConfigSource) {
initialize();
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
xds_stream_->finishGrpcStream(Grpc::Status::Ok);
}
// Validates that the initial xDS request batches all resources referred to in static config
TEST_P(AdsIntegrationTest, XdsBatching) {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
bootstrap.mutable_dynamic_resources()->clear_cds_config();
bootstrap.mutable_dynamic_resources()->clear_lds_config();
auto static_resources = bootstrap.mutable_static_resources();
static_resources->add_clusters()->MergeFrom(buildCluster("eds_cluster"));
static_resources->add_clusters()->MergeFrom(buildCluster("eds_cluster2"));
static_resources->add_listeners()->MergeFrom(buildListener("rds_listener", "route_config"));
static_resources->add_listeners()->MergeFrom(buildListener("rds_listener2", "route_config2"));
});
on_server_init_function_ = [this]() {
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"eds_cluster2", "eds_cluster"},
{"eds_cluster2", "eds_cluster"}, {}));
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("eds_cluster"), buildClusterLoadAssignment("eds_cluster2")},
{buildClusterLoadAssignment("eds_cluster"), buildClusterLoadAssignment("eds_cluster2")}, {},
"1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config2", "route_config"},
{"route_config2", "route_config"}, {}));
sendDiscoveryResponse<envoy::api::v2::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration,
{buildRouteConfig("route_config2", "eds_cluster2"),
buildRouteConfig("route_config", "dummy_cluster")},
{buildRouteConfig("route_config2", "eds_cluster2"),
buildRouteConfig("route_config", "dummy_cluster")},
{}, "1");
};
initialize();
}
// Validates that listeners can be removed before server start.
TEST_P(AdsIntegrationTest, ListenerDrainBeforeServerStart) {
initialize();
sendDiscoveryResponse<envoy::api::v2::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::api::v2::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
test_server_->waitForGaugeGe("listener_manager.total_listeners_active", 1);
// Remove listener.
sendDiscoveryResponse<envoy::api::v2::Listener>(Config::TypeUrl::get().Listener, {}, {}, {}, "1");
test_server_->waitForGaugeEq("listener_manager.total_listeners_active", 0);
}
} // namespace
} // namespace Envoy