@@ -102,7 +102,6 @@ public void chunkedRequest(String scheme) throws Exception {
102102 }
103103 }
104104
105- @ SuppressWarnings ({"SpellCheckingInspection" , "GrazieInspection" })
106105 @ Test (dataProvider = "schemes" )
107106 public void chunkedRequest_doNotReadTheInputStream (String scheme ) throws Exception {
108107 // Use a large chunked request
@@ -140,7 +139,8 @@ public void chunkedRequest_doNotReadTheInputStream(String scheme) throws Excepti
140139 URI uri = makeURI (scheme , "" );
141140
142141 // This ensures we are not just passing the test because we interrupt the InputStream and cause it to not hang.
143- for (int i = 0 ; i < 10 ; i ++) {
142+ int iterations = 50 ;
143+ for (int i = 0 ; i < iterations ; i ++) {
144144 var response = client .send (HttpRequest .newBuilder ()
145145 .uri (uri )
146146 .header (Headers .ContentType , "text/plain" )
@@ -154,13 +154,11 @@ public void chunkedRequest_doNotReadTheInputStream(String scheme) throws Excepti
154154
155155 assertEquals (response .statusCode (), 200 );
156156 assertEquals (response .body (), ExpectedResponse );
157- // We didn't read the InputStream, but the drain() will have - so this will count as a chunkedRequest.
158- // - Note if you run this a bunch of times in a tight loop this next check doesn't always line up. I think it is because of the
159- // Java HTTP client being slow. If I just run it 10 times in a loop it is fine, if I run it 100 times in a loop it fails interminttentl
160- // and the error is the chunked requests don't match the iteration count. I can confirm the getChunkedRequests() matches
161- // the number of times we commit the InputStream which causes us to mark the request as chunked.
162- assertEquals (instrumenter .getChunkedRequests (), i + 1 );
163157 }
158+
159+ // Expect that we counted the correct number of chunked requests.
160+ long chunkedRequests = instrumenter .getChunkedRequests ();
161+ assertEquals (chunkedRequests , iterations );
164162 }
165163 }
166164
0 commit comments