Skip to content

Commit

Permalink
PF can choose either backend due to happy eyeballs
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth committed Sep 11, 2024
1 parent d743b83 commit 776cf9c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions test/cpp/end2end/grpclb_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,12 +952,19 @@ TEST_F(GrpclbEnd2endTest, UsePickFirstChildPolicy) {
"}");
SendBalancerResponse(BuildResponseForBackends(GetBackendPorts(), {}));
CheckRpcSendOk(kNumRpcs, 3000 /* timeout_ms */, true /* wait_for_ready */);
// Check that all requests went to the first backend. This verifies
// Check that all requests went to the one backend. This verifies
// that we used pick_first instead of round_robin as the child policy.
EXPECT_EQ(backends_[0]->service().request_count(), kNumRpcs);
for (size_t i = 1; i < backends_.size(); ++i) {
EXPECT_EQ(backends_[i]->service().request_count(), 0UL);
bool found = false;
for (size_t i = 0; i < backends_.size(); ++i) {
if (backends_[i]->service().request_count() > 0) {
LOG(INFO) << "backend " << i << " saw traffic";
EXPECT_EQ(backends_[i]->service().request_count(), kNumRpcs)
<< "backend " << i;
EXPECT_FALSE(found) << "multiple backends saw traffic";
found = true;
}
}
EXPECT_TRUE(found) << "no backends saw traffic";
// The balancer got a single request.
EXPECT_EQ(1U, balancer_->service().request_count());
// and sent a single response.
Expand All @@ -982,10 +989,19 @@ TEST_F(GrpclbEnd2endTest, SwapChildPolicy) {
"}");
SendBalancerResponse(BuildResponseForBackends(GetBackendPorts(), {}));
CheckRpcSendOk(kNumRpcs, 3000 /* timeout_ms */, true /* wait_for_ready */);
// Check that all requests went to the first backend. This verifies
// Check that all requests went to the one backend. This verifies
// that we used pick_first instead of round_robin as the child policy.
EXPECT_EQ(backends_[0]->service().request_count(), kNumRpcs);
EXPECT_EQ(backends_[1]->service().request_count(), 0UL);
bool found = false;
for (size_t i = 0; i < backends_.size(); ++i) {
if (backends_[i]->service().request_count() > 0) {
LOG(INFO) << "backend " << i << " saw traffic";
EXPECT_EQ(backends_[i]->service().request_count(), kNumRpcs)
<< "backend " << i;
EXPECT_FALSE(found) << "multiple backends saw traffic";
found = true;
}
}
EXPECT_TRUE(found) << "no backends saw traffic";
// Send new resolution that removes child policy from service config.
SetNextResolutionDefaultBalancer();
// We should now be using round_robin, which will send traffic to all
Expand Down

0 comments on commit 776cf9c

Please sign in to comment.