diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 01d9e3bc01c9a1..21264dc0a85818 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -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. @@ -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