From da64bb8a71e25ce0464cfb1a0250649f06e96819 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Thu, 22 Aug 2024 14:40:05 +0100 Subject: [PATCH] Better exception message for ShutdownNow --- test/jdk/java/net/httpclient/ShutdownNow.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/jdk/java/net/httpclient/ShutdownNow.java b/test/jdk/java/net/httpclient/ShutdownNow.java index 5eba01d3b47ae..ed75812ddab77 100644 --- a/test/jdk/java/net/httpclient/ShutdownNow.java +++ b/test/jdk/java/net/httpclient/ShutdownNow.java @@ -210,15 +210,16 @@ void testConcurrent(String uriString) throws Exception { } CompletableFuture.allOf(responses.toArray(new CompletableFuture[0])).get(); } finally { - if (client.awaitTermination(Duration.ofMillis(2000))) { + if (client.awaitTermination(Duration.ofMillis(2500))) { out.println("Client terminated within expected delay"); + assertTrue(client.isTerminated()); } else { - System.out.println(TRACKER.diagnose(client)); - if (client.awaitTermination(Duration.ofMillis(500))) { - throw new AssertionError("client still running: " + TRACKER.diagnose(client)); - } + client = null; + var error = TRACKER.check(500); + if (error != null) throw error; + throw new AssertionError("client was still running, but exited after further delay: " + + "timeout should be adjusted"); } - assertTrue(client.isTerminated()); } } @@ -275,15 +276,16 @@ void testSequential(String uriString) throws Exception { }).thenCompose((c) -> c).get(); } } finally { - if (client.awaitTermination(Duration.ofMillis(2000))) { + if (client.awaitTermination(Duration.ofMillis(2500))) { out.println("Client terminated within expected delay"); + assertTrue(client.isTerminated()); } else { - System.out.println(TRACKER.diagnose(client)); - if (client.awaitTermination(Duration.ofMillis(500))) { - throw new AssertionError("client still running: " + TRACKER.diagnose(client)); - } + client = null; + var error = TRACKER.check(500); + if (error != null) throw error; + throw new AssertionError("client was still running, but exited after further delay: " + + "timeout should be adjusted"); } - assertTrue(client.isTerminated()); } }