Skip to content

Commit 5df00d3

Browse files
committed
8298931: java/net/httpclient/CancelStreamedBodyTest.java fails with AssertionError due to Pending TCP connections: 1
Reviewed-by: jpai
1 parent 36de61c commit 5df00d3

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

test/jdk/java/net/httpclient/CancelStreamedBodyTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public class CancelStreamedBodyTest implements HttpServerAdapters {
104104

105105
static final long SERVER_LATENCY = 75;
106106
static final int ITERATION_COUNT = 3;
107+
static final long CLIENT_SHUTDOWN_GRACE_DELAY = 1500; // milliseconds
107108
// a shared executor helps reduce the amount of threads created by the test
108109
static final Executor executor = new TestExecutor(Executors.newCachedThreadPool());
109110
static final ConcurrentMap<String, Throwable> FAILURES = new ConcurrentHashMap<>();
@@ -287,7 +288,7 @@ public void testAsLines(String uri, boolean sameClient)
287288
if (sameClient) continue;
288289
client = null;
289290
System.gc();
290-
var error = TRACKER.check(tracker, 500);
291+
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
291292
if (error != null) throw error;
292293
}
293294
}
@@ -329,7 +330,7 @@ public void testInputStream(String uri, boolean sameClient)
329330
if (sameClient) continue;
330331
client = null;
331332
System.gc();
332-
var error = TRACKER.check(tracker, 1);
333+
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
333334
if (error != null) throw error;
334335
}
335336
}

test/jdk/java/net/httpclient/ISO_8859_1_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -447,7 +447,7 @@ public void teardown() throws Exception {
447447
sharedClient == null ? null : sharedClient.toString();
448448
sharedClient = null;
449449
Thread.sleep(100);
450-
AssertionError fail = TRACKER.check(500);
450+
AssertionError fail = TRACKER.check(1500);
451451
try {
452452
http1TestServer.stop();
453453
https1TestServer.stop();

test/jdk/java/net/httpclient/ReferenceTracker.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,15 @@ public AssertionError check(Tracker tracker,
214214
long waitStart = System.nanoTime();
215215
long waited = 0;
216216
long toWait = Math.min(graceDelayMs, Math.max(delay, 1));
217-
for (int i = 0; i < count; i++) {
217+
int i = 0;
218+
for (i = 0; i < count; i++) {
218219
if (hasOutstanding.test(tracker)) {
219220
System.gc();
220221
try {
221222
if (i == 0) {
222223
System.out.println("Waiting for HTTP operations to terminate...");
224+
System.out.println("\tgracedelay: " + graceDelayMs
225+
+ " ms, iterations: " + count + ", wait/iteration: " + toWait + "ms");
223226
}
224227
waited += toWait;
225228
Thread.sleep(toWait);
@@ -250,7 +253,8 @@ public AssertionError check(Tracker tracker,
250253
printThreads(msg, System.err);
251254
}
252255
System.out.println("AssertionError: Found some " + description + " in "
253-
+ tracker.getName() + " after " + duration + " ms, waited " + waited + " ms");
256+
+ tracker.getName() + " after " + i + " iterations and " + duration
257+
+ " ms, waited " + waited + " ms");
254258
}
255259
return fail;
256260
}
@@ -261,21 +265,34 @@ public AssertionError check(long graceDelayMs,
261265
boolean printThreads) {
262266
AssertionError fail = null;
263267
graceDelayMs = Math.max(graceDelayMs, 100);
268+
long waitStart = System.nanoTime();
264269
long delay = Math.min(graceDelayMs, 10);
270+
long toWait = Math.min(graceDelayMs, Math.max(delay, 1));
271+
long waited = 0;
265272
var count = delay > 0 ? graceDelayMs / delay : 1;
266-
for (int i = 0; i < count; i++) {
273+
int i = 0;
274+
for (i = 0; i < count; i++) {
267275
if (TRACKERS.stream().anyMatch(hasOutstanding)) {
268276
System.gc();
269277
try {
270278
if (i == 0) {
271279
System.out.println("Waiting for HTTP operations to terminate...");
280+
System.out.println("\tgracedelay: " + graceDelayMs
281+
+ " ms, iterations: " + count + ", wait/iteration: " + toWait + "ms");
272282
}
273-
Thread.sleep(Math.min(graceDelayMs, Math.max(delay, 1)));
283+
waited += toWait;
284+
Thread.sleep(toWait);
274285
} catch (InterruptedException x) {
275286
// OK
276287
}
277-
} else break;
288+
} else {
289+
System.out.println("No outstanding HTTP operations remaining after "
290+
+ i + "/" + count + " iterations and " + waited + "/" + graceDelayMs
291+
+ " ms, (wait/iteration " + toWait + " ms)");
292+
break;
293+
}
278294
}
295+
long duration = Duration.ofNanos(System.nanoTime() - waitStart).toMillis();
279296
if (TRACKERS.stream().anyMatch(hasOutstanding)) {
280297
StringBuilder warnings = diagnose(new StringBuilder(), hasOutstanding);
281298
addSummary(warnings);
@@ -284,14 +301,17 @@ public AssertionError check(long graceDelayMs,
284301
}
285302
} else {
286303
System.out.println("PASSED: No " + description + " found in "
287-
+ getTrackedClientCount() + " clients");
304+
+ getTrackedClientCount() + " clients in " + duration + " ms");
288305
}
289306
if (fail != null) {
290307
Predicate<Tracker> isAlive = Tracker::isSelectorAlive;
291308
if (printThreads && TRACKERS.stream().anyMatch(isAlive)) {
292309
printThreads("Some selector manager threads are still alive: ", System.out);
293310
printThreads("Some selector manager threads are still alive: ", System.err);
294311
}
312+
System.out.println("AssertionError: Found some " + description + " in "
313+
+ getTrackedClientCount() + " clients after " + i + " iterations and " + duration
314+
+ " ms, waited " + waited + " ms");
295315
}
296316
return fail;
297317
}

0 commit comments

Comments
 (0)