diff --git a/test/extensions/clusters/aggregate/cluster_test.cc b/test/extensions/clusters/aggregate/cluster_test.cc index 1156085835eeb..5dd165b18c677 100644 --- a/test/extensions/clusters/aggregate/cluster_test.cc +++ b/test/extensions/clusters/aggregate/cluster_test.cc @@ -249,6 +249,73 @@ TEST_F(AggregateClusterTest, CircuitBreakerMaxConnectionsTest) { EXPECT_EQ(0U, cx_open.value()); } +TEST_F(AggregateClusterTest, CircuitBreakerMaxPendingRequestsTest) { + const std::string yaml_config = R"EOF( + name: aggregate_cluster + connect_timeout: 0.25s + lb_policy: CLUSTER_PROVIDED + circuit_breakers: + thresholds: + - priority: DEFAULT + max_pending_requests: 1 + track_remaining: true + cluster_type: + name: envoy.clusters.aggregate + typed_config: + "@type": type.googleapis.com/envoy.extensions.clusters.aggregate.v3.ClusterConfig + clusters: + - primary + - secondary +)EOF"; + + initialize(yaml_config); + + // resource manager for the DEFAULT priority (look above^) + Upstream::ResourceManager& resource_manager = + cluster_->info()->resourceManager(Upstream::ResourcePriority::Default); + + // get the circuit breaker stats we are interested in, to assert against + Stats::Gauge& rq_pending_open = getCircuitBreakersStatByPriority("default", "rq_pending_open"); + Stats::Gauge& remaining_pending = getCircuitBreakersStatByPriority("default", "remaining_pending"); + + // check the yaml config is set correctly + // we should have a maximum of 1 pending request + EXPECT_EQ(1U, resource_manager.pendingRequests().max()); + + // check that we can create a new pending request + EXPECT_TRUE(resource_manager.pendingRequests().canCreate()); + // check the pending requests count is 0 + EXPECT_EQ(0U, resource_manager.pendingRequests().count()); + // check that we have 1 remaining pending request + EXPECT_EQ(1U, remaining_pending.value()); + // check the circuit breaker is closed + EXPECT_EQ(0U, rq_pending_open.value()); + + // create that one pending request + resource_manager.pendingRequests().inc(); + + // check the pending requests count is now 1 + EXPECT_EQ(1U, resource_manager.pendingRequests().count()); + // make sure we are NOT allowed to create anymore pending requests + EXPECT_FALSE(resource_manager.pendingRequests().canCreate()); + // check that we have 0 remaining pending requests + EXPECT_EQ(0U, remaining_pending.value()); + // check the circuit breaker is now open + EXPECT_EQ(1U, rq_pending_open.value()); + + // remove that one pending request + resource_manager.pendingRequests().dec(); + + // check the pending requests count is now 0 again + EXPECT_EQ(0U, resource_manager.pendingRequests().count()); + // check that we can create a new pending request again + EXPECT_TRUE(resource_manager.pendingRequests().canCreate()); + // check that we have 1 remaining pending request again + EXPECT_EQ(1U, remaining_pending.value()); + // check that the circuit breaker is closed again + EXPECT_EQ(0U, rq_pending_open.value()); +} + TEST_F(AggregateClusterTest, LoadBalancerTest) { initialize(default_yaml_config_); // Health value: