Skip to content

Commit

Permalink
Adding ext_proc MxN test with ext_proc server send out-of-order respo…
Browse files Browse the repository at this point in the history
…nse (#37773)

Adding ext_proc MxN test with ext_proc server send out-of-order
response.
This is to address a left-over comments of the initial MxN PR:
#34942.


Fix: #37064

---------

Signed-off-by: Yanjun Xiang <[email protected]>
  • Loading branch information
yanjunxiang-google authored Jan 2, 2025
1 parent e00a5c9 commit 8e209a4
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions test/extensions/filters/http/ext_proc/ext_proc_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ class ExtProcIntegrationTest : public HttpIntegrationTest,
EXPECT_EQ(std::to_string(status_code), response.headers().getStatusValue());
}

void handleUpstreamRequest(bool add_content_length = false) {
void handleUpstreamRequest(bool add_content_length = false, int status_code = 200) {
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_));
Http::TestResponseHeaderMapImpl response_headers =
Http::TestResponseHeaderMapImpl{{":status", "200"}};
Http::TestResponseHeaderMapImpl{{":status", std::to_string(status_code)}};
uint64_t content_length = 100;
if (add_content_length) {
response_headers.setContentLength(content_length);
Expand Down Expand Up @@ -5180,6 +5180,33 @@ TEST_P(ExtProcIntegrationTest, DuplexStreamedInBothDirection) {
verifyDownstreamResponse(*response, 200);
}

// The ext_proc server sends out-of-order response causing Envoy to shutdown the external
// processing.
TEST_P(ExtProcIntegrationTest, ServerSendOutOfOrderResponseDuplexStreamed) {
const std::string body_sent(8 * 1024, 's');
// Enable FULL_DUPLEX_STREAMED body processing in both directions.
IntegrationStreamDecoderPtr response = initAndSendDataDuplexStreamedMode(body_sent, true, true);

// The ext_proc server receives the request headers and body.
ProcessingRequest header_request;
serverReceiveHeaderDuplexStreamed(header_request);
uint32_t total_req_body_msg = serverReceiveBodyDuplexStreamed(body_sent);

// The ext_proc server should send header response, but it sends back the body response,
// which is out-of-order. This cause Envoy to shut down the external processing, and
// send the buffered HTTP request headers to the upstream.
processor_stream_->startGrpcStream();
serverSendBodyRespDuplexStreamed(total_req_body_msg);

// The backend server processes the request and sends back a 400 response.
handleUpstreamRequest(false, 400);
// The body received by upstream server is expected to be empty.
EXPECT_EQ(upstream_request_->body().toString(), "");
// As the external processing is shut down, the response messages are not sent
// to the ext_proc server. Instead it is sent to the downstream directly.
verifyDownstreamResponse(*response, 400);
}

// The ext_proc server failed to send response in time trigger Envoy HCM stream_idle_timeout.
TEST_P(ExtProcIntegrationTest, ServerWaitTooLongBeforeSendRespDuplexStreamed) {
// Set HCM stream_idle_timeout to be 10s. Note one can also set the
Expand Down

0 comments on commit 8e209a4

Please sign in to comment.