Skip to content

Commit 95310ea

Browse files
committedJan 25, 2024
8223696: java/net/httpclient/MaxStreams.java failed with didn't finish within the time-out
Reviewed-by: dfuchs
1 parent 39b756a commit 95310ea

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed
 

‎test/jdk/java/net/httpclient/MaxStreams.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @summary Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
2828
* @library /test/lib /test/jdk/java/net/httpclient/lib
2929
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
30-
* @run testng/othervm -ea -esa MaxStreams
30+
* @run testng/othervm MaxStreams
3131
*/
3232

3333
import java.io.IOException;
@@ -44,7 +44,6 @@
4444
import java.util.concurrent.CountDownLatch;
4545
import java.util.concurrent.Executors;
4646
import java.util.concurrent.ExecutorService;
47-
import java.util.concurrent.Semaphore;
4847
import javax.net.ssl.SSLContext;
4948
import java.net.http.HttpClient;
5049
import java.net.http.HttpRequest;
@@ -71,9 +70,7 @@ public class MaxStreams {
7170
SSLContext ctx;
7271
String http2FixedURI;
7372
String https2FixedURI;
74-
volatile CountDownLatch latch;
7573
ExecutorService exec;
76-
final Semaphore canStartTestRun = new Semaphore(1);
7774

7875
// we send an initial warm up request, then MAX_STREAMS+1 requests
7976
// in parallel. The last of them should hit the limit.
@@ -95,11 +92,9 @@ public Object[][] variants() {
9592
}
9693

9794

98-
@Test(dataProvider = "uris", timeOut=20000)
95+
@Test(dataProvider = "uris")
9996
void testAsString(String uri) throws Exception {
100-
System.err.println("Semaphore acquire");
101-
canStartTestRun.acquire();
102-
latch = new CountDownLatch(1);
97+
CountDownLatch latch = new CountDownLatch(1);
10398
handler.setLatch(latch);
10499
HttpClient client = HttpClient.newBuilder().sslContext(ctx).build();
105100
List<CompletableFuture<HttpResponse<String>>> responses = new LinkedList<>();
@@ -206,12 +201,11 @@ synchronized CountDownLatch getLatch() {
206201

207202
@Override
208203
public void handle(Http2TestExchange t) throws IOException {
209-
int c = -1;
210204
try (InputStream is = t.getRequestBody();
211205
OutputStream os = t.getResponseBody()) {
212206

213207
is.readAllBytes();
214-
c = counter.getAndIncrement();
208+
int c = counter.getAndIncrement();
215209
if (c > 0 && c <= MAX_STREAMS) {
216210
// Wait for latch.
217211
try {
@@ -220,18 +214,15 @@ public void handle(Http2TestExchange t) throws IOException {
220214
getLatch().await();
221215
System.err.println("Latch resume");
222216
} catch (InterruptedException ee) {}
217+
} else if (c == MAX_STREAMS + 1) {
218+
// client issues MAX_STREAMS + 3 requests in total
219+
// but server should only see MAX_STREAMS + 2 in total. One is rejected by client
220+
// counter c captured before increment so final value is MAX_STREAMS + 1
221+
System.err.println("Counter reset");
222+
counter.set(0);
223223
}
224224
t.sendResponseHeaders(200, RESPONSE.length());
225225
os.write(RESPONSE.getBytes());
226-
} finally {
227-
// client issues MAX_STREAMS + 3 requests in total
228-
// but server should only see MAX_STREAMS + 2 in total. One is rejected by client
229-
// counter c captured before increment so final value is MAX_STREAMS + 1
230-
if (c == MAX_STREAMS + 1) {
231-
System.err.println("Semaphore release");
232-
counter.set(0);
233-
canStartTestRun.release();
234-
}
235226
}
236227
}
237228
}

0 commit comments

Comments
 (0)
Please sign in to comment.