test/jdk/java/net/httpclient/ThrowingSubscribers.java
branchhttp-client-branch
changeset 56423 ba64c30666cc
parent 56410 1b37529eaf3a
child 56426 f39b316f10c9
--- a/test/jdk/java/net/httpclient/ThrowingSubscribers.java	Wed Apr 11 15:21:25 2018 +0100
+++ b/test/jdk/java/net/httpclient/ThrowingSubscribers.java	Fri Apr 13 10:49:17 2018 +0100
@@ -26,7 +26,8 @@
  * @summary Tests what happens when response body handlers and subscribers
  *          throw unexpected exceptions.
  * @library /lib/testlibrary http2/server
- * @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters ThrowingSubscribers
+ * @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters
+  *       ReferenceTracker ThrowingSubscribers
  * @modules java.base/sun.net.www.http
  *          java.net.http/jdk.internal.net.http.common
  *          java.net.http/jdk.internal.net.http.frame
@@ -117,6 +118,7 @@
         return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan);
     }
 
+    final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE;
     private volatile HttpClient sharedClient;
 
     static class TestExecutor implements Executor {
@@ -211,10 +213,11 @@
 
     private HttpClient makeNewClient() {
         clientCount.incrementAndGet();
-        return HttpClient.newBuilder()
+        HttpClient client =  HttpClient.newBuilder()
                 .executor(executor)
                 .sslContext(sslContext)
                 .build();
+        return TRACKER.track(client);
     }
 
     HttpClient newHttpClient(boolean share) {
@@ -677,11 +680,24 @@
 
     @AfterTest
     public void teardown() throws Exception {
+        String sharedClientName =
+                sharedClient == null ? null : sharedClient.toString();
         sharedClient = null;
-        httpTestServer.stop();
-        httpsTestServer.stop();
-        http2TestServer.stop();
-        https2TestServer.stop();
+        Thread.sleep(100);
+        AssertionError fail = TRACKER.check(500);
+        try {
+            httpTestServer.stop();
+            httpsTestServer.stop();
+            http2TestServer.stop();
+            https2TestServer.stop();
+        } finally {
+            if (fail != null) {
+                if (sharedClientName != null) {
+                    System.err.println("Shared client name is: " + sharedClientName);
+                }
+                throw fail;
+            }
+        }
     }
 
     static class HTTP_FixedLengthHandler implements HttpTestHandler {