Skip to content

8314136: Test java/net/httpclient/CancelRequestTest.java failed: WARNING: tracker for HttpClientImpl(42) has outstanding operations #1686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions test/jdk/java/net/httpclient/CancelRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
*/
// * -Dseed=3582896013206826205L
// * -Dseed=5784221742235559231L
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import jdk.internal.net.http.common.OperationTrackers.Tracker;
import jdk.test.lib.RandomFactory;
import jdk.test.lib.net.SimpleSSLContext;
Expand All @@ -56,8 +53,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.Reference;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpConnectTimeoutException;
Expand All @@ -80,17 +75,15 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.httpclient.test.lib.common.HttpServerAdapters;
import jdk.httpclient.test.lib.http2.Http2TestServer;

import static java.lang.System.arraycopy;
import static java.lang.System.out;
import static java.lang.System.err;
import static java.net.http.HttpClient.Version.HTTP_1_1;
import static java.net.http.HttpClient.Version.HTTP_2;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class CancelRequestTest implements HttpServerAdapters {
Expand Down Expand Up @@ -179,19 +172,19 @@ void beforeMethod(ITestContext context) {
}

@AfterClass
static final void printFailedTests(ITestContext context) {
static void printFailedTests(ITestContext context) {
out.println("\n=========================");
var failed = context.getFailedTests().getAllResults().stream()
.collect(Collectors.toMap(r -> name(r), ITestResult::getThrowable));
.collect(Collectors.toMap(CancelRequestTest::name, ITestResult::getThrowable));
FAILURES.putAll(failed);
try {
out.printf("%n%sCreated %d servers and %d clients%n",
now(), serverCount.get(), clientCount.get());
if (FAILURES.isEmpty()) return;
out.println("Failed tests: ");
FAILURES.entrySet().forEach((e) -> {
out.printf("\t%s: %s%n", e.getKey(), e.getValue());
e.getValue().printStackTrace(out);
FAILURES.forEach((key, value) -> {
out.printf("\t%s: %s%n", key, value);
value.printStackTrace(out);
});
if (tasksFailed) {
System.out.println("WARNING: Some tasks failed");
Expand Down Expand Up @@ -327,7 +320,7 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
out.println("cf2 after cancel: " + cf2);
try {
String body = cf2.get().body();
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
assertEquals(body, String.join("", BODY.split("\\|")));
throw new AssertionError("Expected CancellationException not received");
} catch (ExecutionException x) {
out.println("Got expected exception: " + x);
Expand All @@ -348,14 +341,14 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
// completed yet - so wait for it here...
try {
String body = response.get().body();
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
assertEquals(body, String.join("", BODY.split("\\|")));
if (mayInterruptIfRunning) {
// well actually - this could happen... In which case we'll need to
// increase the latency in the server handler...
throw new AssertionError("Expected Exception not received");
}
} catch (ExecutionException x) {
assertEquals(response.isDone(), true);
assertTrue(response.isDone());
Throwable wrapped = x.getCause();
Throwable cause = wrapped;
if (mayInterruptIfRunning) {
Expand Down Expand Up @@ -383,11 +376,11 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
}
}

assertEquals(response.isDone(), true);
assertEquals(response.isCancelled(), false);
assertTrue(response.isDone());
assertFalse(response.isCancelled());
assertEquals(cf1.isCancelled(), hasCancellationException);
assertEquals(cf2.isDone(), true);
assertEquals(cf2.isCancelled(), false);
assertTrue(cf2.isDone());
assertFalse(cf2.isCancelled());
assertEquals(latch.getCount(), 0);

var error = TRACKER.check(tracker, 1000,
Expand All @@ -397,6 +390,8 @@ public void testGetSendAsync(String uri, boolean sameClient, boolean mayInterrup
Reference.reachabilityFence(client);
if (error != null) throw error;
}
assert client != null;
if (!sameClient) client.close();
}

@Test(dataProvider = "asyncurls")
Expand All @@ -413,7 +408,7 @@ public void testPostSendAsync(String uri, boolean sameClient, boolean mayInterru

CompletableFuture<CompletableFuture<?>> cancelFuture = new CompletableFuture<>();

Iterable<byte[]> iterable = new Iterable<byte[]>() {
Iterable<byte[]> iterable = new Iterable<>() {
@Override
public Iterator<byte[]> iterator() {
// this is dangerous
Expand Down Expand Up @@ -448,7 +443,7 @@ public Iterator<byte[]> iterator() {
out.println("cf2 after cancel: " + cf2);
try {
String body = cf2.get().body();
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
assertEquals(body, String.join("", BODY.split("\\|")));
throw new AssertionError("Expected CancellationException not received");
} catch (ExecutionException x) {
out.println("Got expected exception: " + x);
Expand All @@ -469,14 +464,14 @@ public Iterator<byte[]> iterator() {
// completed yet - so wait for it here...
try {
String body = response.get().body();
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
assertEquals(body, String.join("", BODY.split("\\|")));
if (mayInterruptIfRunning) {
// well actually - this could happen... In which case we'll need to
// increase the latency in the server handler...
throw new AssertionError("Expected Exception not received");
}
} catch (ExecutionException x) {
assertEquals(response.isDone(), true);
assertTrue(response.isDone());
Throwable wrapped = x.getCause();
assertTrue(CancellationException.class.isAssignableFrom(wrapped.getClass()));
Throwable cause = wrapped.getCause();
Expand All @@ -495,11 +490,11 @@ public Iterator<byte[]> iterator() {
}
}

assertEquals(response.isDone(), true);
assertEquals(response.isCancelled(), false);
assertTrue(response.isDone());
assertFalse(response.isCancelled());
assertEquals(cf1.isCancelled(), hasCancellationException);
assertEquals(cf2.isDone(), true);
assertEquals(cf2.isCancelled(), false);
assertTrue(cf2.isDone());
assertFalse(cf2.isCancelled());
assertEquals(latch.getCount(), 0);

var error = TRACKER.check(tracker, 1000,
Expand All @@ -509,6 +504,8 @@ public Iterator<byte[]> iterator() {
Reference.reachabilityFence(client);
if (error != null) throw error;
}
assert client != null;
if (!sameClient) client.close();
}

@Test(dataProvider = "urls")
Expand Down Expand Up @@ -572,17 +569,19 @@ public void testPostInterrupt(String uri, boolean sameClient)
} else {
assert failed == null;
out.println(uriStr + ": got body: " + body);
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
assertEquals(body, String.join("", BODY.split("\\|")));
}
out.println("next iteration");

var error = TRACKER.check(tracker, 1000,
var error = TRACKER.check(tracker, 2000,
(t) -> t.getOutstandingOperations() > 0 || t.getOutstandingSubscribers() > 0,
"subscribers for testPostInterrupt(%s)\n\t step [%s]".formatted(req.uri(), i),
false);
Reference.reachabilityFence(client);
if (error != null) throw error;
}
assert client != null;
if (!sameClient) client.close();
}


Expand Down