Skip to content

Commit

Permalink
8223696: java/net/httpclient/MaxStreams.java failed with didn't finis…
Browse files Browse the repository at this point in the history
…h within the time-out

Backport-of: 95310eab6ce73512b1afc0a7a26a396dd7b6cb7c
  • Loading branch information
GoeLin committed Mar 19, 2024
1 parent 700fd39 commit 196a851
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions test/jdk/java/net/httpclient/MaxStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @summary Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* @run testng/othervm -ea -esa MaxStreams
* @run testng/othervm MaxStreams
*/

import java.io.IOException;
Expand All @@ -45,7 +45,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Semaphore;
import javax.net.ssl.SSLContext;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Expand Down Expand Up @@ -74,9 +73,7 @@ public class MaxStreams {
SSLContext ctx;
String http2FixedURI;
String https2FixedURI;
volatile CountDownLatch latch;
ExecutorService exec;
final Semaphore canStartTestRun = new Semaphore(1);

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


@Test(dataProvider = "uris", timeOut=20000)
@Test(dataProvider = "uris")
void testAsString(String uri) throws Exception {
System.err.println("Semaphore acquire");
canStartTestRun.acquire();
latch = new CountDownLatch(1);
CountDownLatch latch = new CountDownLatch(1);
handler.setLatch(latch);
HttpClient client = HttpClient.newBuilder().sslContext(ctx).build();
List<CompletableFuture<HttpResponse<String>>> responses = new LinkedList<>();
Expand Down Expand Up @@ -209,12 +204,11 @@ synchronized CountDownLatch getLatch() {

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

is.readAllBytes();
c = counter.getAndIncrement();
int c = counter.getAndIncrement();
if (c > 0 && c <= MAX_STREAMS) {
// Wait for latch.
try {
Expand All @@ -223,18 +217,15 @@ public void handle(Http2TestExchange t) throws IOException {
getLatch().await();
System.err.println("Latch resume");
} catch (InterruptedException ee) {}
} else if (c == MAX_STREAMS + 1) {
// client issues MAX_STREAMS + 3 requests in total
// but server should only see MAX_STREAMS + 2 in total. One is rejected by client
// counter c captured before increment so final value is MAX_STREAMS + 1
System.err.println("Counter reset");
counter.set(0);
}
t.sendResponseHeaders(200, RESPONSE.length());
os.write(RESPONSE.getBytes());
} finally {
// client issues MAX_STREAMS + 3 requests in total
// but server should only see MAX_STREAMS + 2 in total. One is rejected by client
// counter c captured before increment so final value is MAX_STREAMS + 1
if (c == MAX_STREAMS + 1) {
System.err.println("Semaphore release");
counter.set(0);
canStartTestRun.release();
}
}
}
}
Expand Down

1 comment on commit 196a851

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.