Skip to content

Commit

Permalink
ext_proc: fix the flaky test (#34043)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Tianyu Xia <tyxia@google.com>
  • Loading branch information
tyxia committed May 13, 2024
1 parent 25af3dd commit 770fc9c
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions test/extensions/filters/http/rate_limit_quota/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,21 @@ TEST_P(RateLimitQuotaIntegrationTest, DISABLED_MultiRequestWithTokenBucketThrott
}
}

TEST_P(RateLimitQuotaIntegrationTest, TwoRequestWithTokenBucketThrottling) {
TEST_P(RateLimitQuotaIntegrationTest, MultiRequestWithTokenBucket) {
initializeConfig();
HttpIntegrationTest::initialize();
absl::flat_hash_map<std::string, std::string> custom_headers = {{"environment", "staging"},
{"group", "envoy"}};
int max_token = 0;
// First request: allowed; fail-open, default no assignment policy.
// Second request: rejected; no token remaining.
for (int i = 0; i < 2; ++i) {
int max_token = 1;
int tokens_per_fill = 30;
int fill_interval_sec = 60;
int fill_one_token_in_ms = fill_interval_sec / tokens_per_fill * 1000;
for (int i = 0; i < 10; ++i) {
// We advance time by 2s so that token bucket can be refilled.
if (i == 4 || i == 6) {
simTime().advanceTimeAndRun(std::chrono::milliseconds(fill_one_token_in_ms), *dispatcher_,
Envoy::Event::Dispatcher::RunType::NonBlock);
}
// Send downstream client request to upstream.
sendClientRequest(&custom_headers);

Expand Down Expand Up @@ -765,25 +771,6 @@ TEST_P(RateLimitQuotaIntegrationTest, TwoRequestWithTokenBucketThrottling) {
rlqs_stream_->sendGrpcMessage(rlqs_response);
}

if (i == 1) {
ASSERT_TRUE(response_->waitForEndStream());
EXPECT_TRUE(response_->complete());
EXPECT_EQ(response_->headers().getStatusValue(), "429");
} else {
// Handle the request received by upstream.
ASSERT_TRUE(
fake_upstreams_[0]->waitForHttpConnection(*dispatcher_, fake_upstream_connection_));
ASSERT_TRUE(fake_upstream_connection_->waitForNewStream(*dispatcher_, upstream_request_));
ASSERT_TRUE(upstream_request_->waitForEndStream(*dispatcher_));
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, false);
upstream_request_->encodeData(100, true);

// Verify the response to downstream.
ASSERT_TRUE(response_->waitForEndStream());
EXPECT_TRUE(response_->complete());
EXPECT_EQ(response_->headers().getStatusValue(), "200");
}

cleanUp();
}
}
Expand Down

0 comments on commit 770fc9c

Please sign in to comment.