@@ -1520,6 +1520,77 @@ TEST_F(ClusterManagerImplTest, OriginalDstInitialization) {
1520
1520
factory_.tls_ .shutdownThread ();
1521
1521
}
1522
1522
1523
+ TEST_F (ClusterManagerImplTest, GetActiveOrWarmingCluster) {
1524
+ // Start with a static cluster.
1525
+ const std::string bootstrap_yaml = R"EOF(
1526
+ static_resources:
1527
+ clusters:
1528
+ - name: static_cluster
1529
+ connect_timeout: 0.250s
1530
+ type: static
1531
+ lb_policy: round_robin
1532
+ load_assignment:
1533
+ cluster_name: static_cluster
1534
+ endpoints:
1535
+ - lb_endpoints:
1536
+ - endpoint:
1537
+ address:
1538
+ socket_address:
1539
+ address: 127.0.0.1
1540
+ port_value: 11001
1541
+ )EOF" ;
1542
+ create (parseBootstrapFromV3Yaml (bootstrap_yaml));
1543
+
1544
+ // Static cluster should be active.
1545
+ EXPECT_NE (absl::nullopt , cluster_manager_->getActiveCluster (" static_cluster" ));
1546
+ EXPECT_NE (absl::nullopt , cluster_manager_->getActiveOrWarmingCluster (" static_cluster" ));
1547
+ EXPECT_EQ (absl::nullopt , cluster_manager_->getActiveOrWarmingCluster (" non_existent_cluster" ));
1548
+
1549
+ // Now, add a dynamic cluster. It will start in warming state.
1550
+ const std::string warming_cluster_yaml = R"EOF(
1551
+ name: warming_cluster
1552
+ connect_timeout: 0.250s
1553
+ type: EDS
1554
+ eds_cluster_config:
1555
+ eds_config:
1556
+ api_config_source:
1557
+ api_type: GRPC
1558
+ grpc_services:
1559
+ envoy_grpc:
1560
+ cluster_name: static_cluster
1561
+ )EOF" ;
1562
+ auto warming_cluster_config = parseClusterFromV3Yaml (warming_cluster_yaml);
1563
+
1564
+ // Mock the cluster creation for the warming cluster.
1565
+ std::shared_ptr<MockClusterMockPrioritySet> warming_cluster =
1566
+ std::make_shared<NiceMock<MockClusterMockPrioritySet>>();
1567
+ warming_cluster->info_ ->name_ = " warming_cluster" ;
1568
+ std::function<void ()> cluster_init_callback;
1569
+ EXPECT_CALL (*warming_cluster, initialize (_)).WillOnce (SaveArg<0 >(&cluster_init_callback));
1570
+ EXPECT_CALL (factory_, clusterFromProto_ (ProtoEq (warming_cluster_config), _, true ))
1571
+ .WillOnce (Return (std::make_pair (warming_cluster, nullptr )));
1572
+
1573
+ // Add the cluster.
1574
+ EXPECT_TRUE (*cluster_manager_->addOrUpdateCluster (warming_cluster_config, " version1" ));
1575
+
1576
+ // The cluster should be in warming, not active.
1577
+ EXPECT_EQ (absl::nullopt , cluster_manager_->getActiveCluster (" warming_cluster" ));
1578
+ OptRef<const Cluster> cluster = cluster_manager_->getActiveOrWarmingCluster (" warming_cluster" );
1579
+ EXPECT_NE (absl::nullopt , cluster);
1580
+ EXPECT_EQ (" warming_cluster" , cluster->info ()->name ());
1581
+
1582
+ // Finish initialization. This should move it to active.
1583
+ cluster_init_callback ();
1584
+
1585
+ // Now the cluster should be active.
1586
+ cluster = cluster_manager_->getActiveCluster (" warming_cluster" );
1587
+ EXPECT_NE (absl::nullopt , cluster);
1588
+ EXPECT_EQ (" warming_cluster" , cluster->info ()->name ());
1589
+ cluster = cluster_manager_->getActiveOrWarmingCluster (" warming_cluster" );
1590
+ EXPECT_NE (absl::nullopt , cluster);
1591
+ EXPECT_EQ (" warming_cluster" , cluster->info ()->name ());
1592
+ }
1593
+
1523
1594
TEST_F (ClusterManagerImplTest, UpstreamSocketOptionsPassedToTcpConnPool) {
1524
1595
createWithBasicStaticCluster ();
1525
1596
NiceMock<MockLoadBalancerContext> context;
0 commit comments