Skip to content

Commit bae0117

Browse files
authored
network_ext_proc: improve intergation tests due to TCP read segmentation (#39688)
Commit Message: Additional Description: Risk Level: low Testing: low --------- Signed-off-by: Boteng Yao <[email protected]>
1 parent 84db051 commit bae0117

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

test/extensions/filters/network/ext_proc/ext_proc_integration_test.cc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,20 +662,53 @@ TEST_P(NetworkExtProcFilterIntegrationTest, MultipleDataChunks) {
662662
EXPECT_EQ(request1.read_data().end_of_stream(), false);
663663

664664
sendReadGrpcMessage("chunk1_processed", false, true);
665-
ASSERT_TRUE(fake_upstream_connection->waitForData(16));
665+
size_t total_upstream_data = 16; // Already received "chunk1_processed"
666+
ASSERT_TRUE(fake_upstream_connection->waitForData(total_upstream_data)); // "chunk1_processed"
666667

667668
ASSERT_TRUE(tcp_client->write("chunk2", true));
668669

669-
// Second chunk should also be sent to ext_proc
670670
ProcessingRequest request2;
671671
ASSERT_TRUE(processor_stream_->waitForGrpcMessage(*dispatcher_, request2));
672672
EXPECT_EQ(request2.has_read_data(), true);
673-
EXPECT_EQ(request2.read_data().data(), "chunk2");
674-
EXPECT_EQ(request2.read_data().end_of_stream(), true);
675673

676-
// Respond to second chunk
677-
sendReadGrpcMessage("chunk2_processed", true);
678-
ASSERT_TRUE(fake_upstream_connection->waitForData(16));
674+
// Handle potential TCP fragmentation
675+
if (!request2.read_data().end_of_stream()) {
676+
// We got partial data without end_of_stream
677+
std::string partial_response = request2.read_data().data() + "_processed";
678+
sendReadGrpcMessage(partial_response, false);
679+
680+
// Wait for upstream to receive the partial data
681+
total_upstream_data += partial_response.length();
682+
ASSERT_TRUE(fake_upstream_connection->waitForData(total_upstream_data));
683+
684+
// Wait for the final message with end_of_stream
685+
ProcessingRequest request3;
686+
ASSERT_TRUE(processor_stream_->waitForGrpcMessage(*dispatcher_, request3));
687+
EXPECT_EQ(request3.has_read_data(), true);
688+
EXPECT_EQ(request3.read_data().end_of_stream(), true);
689+
690+
// Respond to the final message
691+
std::string final_response = request3.read_data().data() + "_processed";
692+
sendReadGrpcMessage(final_response, true);
693+
694+
// Wait for the final data if non-empty
695+
if (!request3.read_data().data().empty()) {
696+
total_upstream_data += final_response.length();
697+
ASSERT_TRUE(fake_upstream_connection->waitForData(total_upstream_data));
698+
}
699+
} else {
700+
// We got the complete chunk2 with end_of_stream in one message
701+
EXPECT_EQ(request2.read_data().data(), "chunk2");
702+
EXPECT_EQ(request2.read_data().end_of_stream(), true);
703+
704+
sendReadGrpcMessage("chunk2_processed", true);
705+
706+
total_upstream_data += 16; // "chunk2_processed"
707+
ASSERT_TRUE(fake_upstream_connection->waitForData(total_upstream_data));
708+
}
709+
710+
// Wait for half-close to ensure end_of_stream was properly propagated
711+
ASSERT_TRUE(fake_upstream_connection->waitForHalfClose());
679712

680713
ASSERT_TRUE(fake_upstream_connection->close());
681714
tcp_client->close();

0 commit comments

Comments
 (0)