Skip to content

Commit

Permalink
fix flake in http_subset_integration_test (#8655)
Browse files Browse the repository at this point in the history
The RANDOM and LEAST_REQUEST load balancer policies randomly choose hosts
and 10 iterations isn't enough to guarantee they'll choose both hosts in
the subset.

Risk Level: low, test only
Testing: fixes tests
Docs Changes: n/a
Release Notes: n/a
Fixes: #8643

Signed-off-by: Stephan Zuercher <[email protected]>
  • Loading branch information
zuercher authored and lizan committed Oct 18, 2019
1 parent 2fe5b8a commit 87d496d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/integration/http_subset_lb_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ class HttpSubsetLbIntegrationTest : public testing::TestWithParam<envoy::api::v2
// Runs a subset lb test with the given request headers, expecting the x-host-type header to
// the given type ("a" or "b"). If is_hash_lb_, verifies that a single host is selected over n
// iterations (e.g. for maglev/hash-ring policies). Otherwise, expected more than one host to be
// selected over n iterations.
// selected over at least n iterations and at most m.
void runTest(Http::TestHeaderMapImpl& request_headers, const std::string expected_host_type,
const int n = 10) {
const int n = 100, const int m = 1000) {
ASSERT_LT(n, m);

std::set<std::string> hosts;
for (int i = 0; i < n; i++) {
for (int i = 0; i < m; i++) {
Http::TestHeaderMapImpl response_headers{{":status", "200"}};

// Send header only request.
Expand All @@ -160,6 +162,12 @@ class HttpSubsetLbIntegrationTest : public testing::TestWithParam<envoy::api::v2
.get(Envoy::Http::LowerCaseString{host_header_})
->value()
.getStringView());

if (i >= n && (is_hash_lb_ || hosts.size() > 1)) {
// Once we've completed n iterations, quit for hash lb policies. For others, keep going
// until we've seen multiple hosts (as expected) or reached m iterations.
break;
}
}

if (is_hash_lb_) {
Expand Down

0 comments on commit 87d496d

Please sign in to comment.