@@ -662,20 +662,53 @@ TEST_P(NetworkExtProcFilterIntegrationTest, MultipleDataChunks) {
662
662
EXPECT_EQ (request1.read_data ().end_of_stream (), false );
663
663
664
664
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"
666
667
667
668
ASSERT_TRUE (tcp_client->write (" chunk2" , true ));
668
669
669
- // Second chunk should also be sent to ext_proc
670
670
ProcessingRequest request2;
671
671
ASSERT_TRUE (processor_stream_->waitForGrpcMessage (*dispatcher_, request2));
672
672
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 );
675
673
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 ());
679
712
680
713
ASSERT_TRUE (fake_upstream_connection->close ());
681
714
tcp_client->close ();
0 commit comments