ok2c commented on code in PR #711:
URL: 
https://github.com/apache/httpcomponents-core/pull/711#discussion_r4142107088


##########
httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java:
##########
@@ -2026,52 +2026,68 @@ void 
testGoAwayReservedBitInLastStreamIdAffectsStreamCulling() throws Exception
                 h2StreamListener,
                 () -> streamHandler);
 
-        // Create 3 remote (even) streams by feeding inbound HEADERS on 2,4,6.
-        final ByteArrayBuffer headerBuf = new ByteArrayBuffer(256);
-        final HPackEncoder encoder = new HPackEncoder(
-                H2Config.INIT.getHeaderTableSize(),
-                CharCodingSupport.createEncoder(CharCodingConfig.DEFAULT));
+        // Create 3 local (odd) streams: 1, 3, 5.
+        final H2StreamHandler streamHandler1 = 
Mockito.mock(H2StreamHandler.class);
+        final H2StreamHandler streamHandler3 = 
Mockito.mock(H2StreamHandler.class);
+        final H2StreamHandler streamHandler5 = 
Mockito.mock(H2StreamHandler.class);
+        mux.createStream(mux.createChannel(1), streamHandler1);
+        mux.createStream(mux.createChannel(3), streamHandler3);
+        mux.createStream(mux.createChannel(5), streamHandler5);
 
-        final List<Header> headers = Arrays.asList(
-                new BasicHeader(":method", "GET"),
-                new BasicHeader(":scheme", "https"),
-                new BasicHeader(":path", "/"),
-                new BasicHeader(":authority", "example.test"));
-        encoder.encodeHeaders(headerBuf, headers, 
h2Config.isCompressionEnabled());
+        // GOAWAY last-stream-id = 4, but with reserved MSB set.
+        // Correct masking keeps streams <= 4 (1 and 3) and drops only stream 
5.
+        final ByteBuffer goAwayPayload = ByteBuffer.allocate(8);
+        goAwayPayload.putInt(0x80000004); // reserved bit set, last-stream-id 
= 4
+        goAwayPayload.putInt(H2Error.NO_ERROR.getCode());
+        goAwayPayload.flip();
 
-        final RawFrame h2 = FRAME_FACTORY.createHeaders(2,
-                ByteBuffer.wrap(headerBuf.array(), 0, headerBuf.length()),
-                true,  // END_HEADERS
-                false  // END_STREAM
-        );
-        final RawFrame h4 = FRAME_FACTORY.createHeaders(4,
-                ByteBuffer.wrap(headerBuf.array(), 0, headerBuf.length()),
-                true,
-                false
-        );
-        final RawFrame h6 = FRAME_FACTORY.createHeaders(6,
-                ByteBuffer.wrap(headerBuf.array(), 0, headerBuf.length()),
-                true,
-                false
-        );
+        final RawFrame goAway = new RawFrame(FrameType.GOAWAY.getValue(), 0, 
0, goAwayPayload);
+
+        Assertions.assertDoesNotThrow(() -> 
mux.onInput(ByteBuffer.wrap(encodeFrame(goAway))));
 
-        feedFrame(mux, h2);
-        feedFrame(mux, h4);
-        feedFrame(mux, h6);
+        Mockito.verify(streamHandler5, 
Mockito.times(1)).failed(exceptionCaptor.capture());
+        
Assertions.assertInstanceOf(org.apache.hc.core5.http.RequestNotExecutedException.class,
 exceptionCaptor.getValue());

Review Comment:
   @rp-arielrodriguez Good catch. 
   
   Please do me a little favor and get rid of fully qualified 
`org.apache.hc.core5.http.RequestNotExecutedException.class`? It can be 
imported. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to