8299325: java/net/httpclient/CancelRequestTest.java fails "test CancelRequestTest.testGetSendAsync("https://localhost:46509/https1/x/same/interrupt", true, true)"
Reviewed-by: jpai
This commit is contained in:
parent
041a12e655
commit
a74ebd048a
@ -86,6 +86,7 @@ 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.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
@ -354,14 +355,22 @@ public class CancelRequestTest implements HttpServerAdapters {
|
||||
} catch (ExecutionException x) {
|
||||
assertEquals(response.isDone(), true);
|
||||
Throwable wrapped = x.getCause();
|
||||
assertTrue(CancellationException.class.isAssignableFrom(wrapped.getClass()));
|
||||
Throwable cause = wrapped.getCause();
|
||||
out.println("CancellationException cause: " + x);
|
||||
assertTrue(IOException.class.isAssignableFrom(cause.getClass()));
|
||||
if (cause instanceof HttpConnectTimeoutException) {
|
||||
cause.printStackTrace(out);
|
||||
throw new RuntimeException("Unexpected timeout exception", cause);
|
||||
Throwable cause = wrapped;
|
||||
if (mayInterruptIfRunning) {
|
||||
assertTrue(CancellationException.class.isAssignableFrom(wrapped.getClass()),
|
||||
"Unexpected exception: " + wrapped);
|
||||
cause = wrapped.getCause();
|
||||
out.println("CancellationException cause: " + x);
|
||||
if (cause instanceof HttpConnectTimeoutException) {
|
||||
cause.printStackTrace(out);
|
||||
throw new RuntimeException("Unexpected timeout exception", cause);
|
||||
}
|
||||
}
|
||||
if (!IOException.class.isInstance(cause)) {
|
||||
out.println("Unexpected cause: " + cause.getClass());
|
||||
cause.printStackTrace(out);
|
||||
}
|
||||
assertTrue(IOException.class.isAssignableFrom(cause.getClass()));
|
||||
if (mayInterruptIfRunning) {
|
||||
out.println("Got expected exception: " + wrapped);
|
||||
out.println("\tcause: " + cause);
|
||||
@ -379,7 +388,7 @@ public class CancelRequestTest implements HttpServerAdapters {
|
||||
assertEquals(cf2.isCancelled(), false);
|
||||
assertEquals(latch.getCount(), 0);
|
||||
|
||||
var error = TRACKER.check(tracker, 200,
|
||||
var error = TRACKER.check(tracker, 1000,
|
||||
(t) -> t.getOutstandingOperations() > 0 || t.getOutstandingSubscribers() > 0,
|
||||
"subscribers for testGetSendAsync(%s)\n\t step [%s]".formatted(req.uri(), i),
|
||||
false);
|
||||
@ -491,7 +500,7 @@ public class CancelRequestTest implements HttpServerAdapters {
|
||||
assertEquals(cf2.isCancelled(), false);
|
||||
assertEquals(latch.getCount(), 0);
|
||||
|
||||
var error = TRACKER.check(tracker, 200,
|
||||
var error = TRACKER.check(tracker, 1000,
|
||||
(t) -> t.getOutstandingOperations() > 0 || t.getOutstandingSubscribers() > 0,
|
||||
"subscribers for testPostSendAsync(%s)\n\t step [%s]".formatted(req.uri(), i),
|
||||
false);
|
||||
@ -513,9 +522,11 @@ public class CancelRequestTest implements HttpServerAdapters {
|
||||
|
||||
Thread main = Thread.currentThread();
|
||||
CompletableFuture<Thread> interruptingThread = new CompletableFuture<>();
|
||||
var uriStr = uri + "/post/req=" + i;
|
||||
Runnable interrupt = () -> {
|
||||
Thread current = Thread.currentThread();
|
||||
out.printf("%s Interrupting main from: %s (%s)", now(), current, uri);
|
||||
out.printf("%s Interrupting main from: %s (%s)%n", now(), current, uriStr);
|
||||
err.printf("%s Interrupting main from: %s (%s)%n", now(), current, uriStr);
|
||||
interruptingThread.complete(current);
|
||||
main.interrupt();
|
||||
};
|
||||
@ -526,36 +537,44 @@ public class CancelRequestTest implements HttpServerAdapters {
|
||||
return List.of(BODY.getBytes(UTF_8)).iterator();
|
||||
};
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(uri))
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(uriStr))
|
||||
.POST(HttpRequest.BodyPublishers.ofByteArrays(iterable))
|
||||
.build();
|
||||
String body = null;
|
||||
Exception failed = null;
|
||||
try {
|
||||
out.println("Sending: " + uriStr);
|
||||
body = client.send(req, BodyHandlers.ofString()).body();
|
||||
} catch (Exception x) {
|
||||
failed = x;
|
||||
}
|
||||
|
||||
out.println(uriStr + ": got result or exception");
|
||||
if (failed instanceof InterruptedException) {
|
||||
out.println("Got expected exception: " + failed);
|
||||
out.println(uriStr + ": Got expected exception: " + failed);
|
||||
} else if (failed instanceof IOException) {
|
||||
out.println(uriStr + ": got IOException: " + failed);
|
||||
// that could be OK if the main thread was interrupted
|
||||
// from the main thread: the interrupt status could have
|
||||
// been caught by writing to the socket from the main
|
||||
// thread.
|
||||
if (interruptingThread.get() == main) {
|
||||
out.println("Accepting IOException: " + failed);
|
||||
if (interruptingThread.isDone() && interruptingThread.get() == main) {
|
||||
out.println(uriStr + ": Accepting IOException: " + failed);
|
||||
failed.printStackTrace(out);
|
||||
} else {
|
||||
out.println(uriStr + ": unexpected exception: " + failed);
|
||||
throw failed;
|
||||
}
|
||||
} else if (failed != null) {
|
||||
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
|
||||
out.println(uriStr + ": unexpected exception: " + failed);
|
||||
throw failed;
|
||||
} else {
|
||||
assert failed == null;
|
||||
out.println(uriStr + ": got body: " + body);
|
||||
assertEquals(body, Stream.of(BODY.split("\\|")).collect(Collectors.joining()));
|
||||
}
|
||||
out.println("next iteration");
|
||||
|
||||
var error = TRACKER.check(tracker, 200,
|
||||
var error = TRACKER.check(tracker, 1000,
|
||||
(t) -> t.getOutstandingOperations() > 0 || t.getOutstandingSubscribers() > 0,
|
||||
"subscribers for testPostInterrupt(%s)\n\t step [%s]".formatted(req.uri(), i),
|
||||
false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user