Skip to content

Commit 8398d6b

Browse files
committed
Backport 5df00d34fe83648fb833dac738a45653865ca426
1 parent 8e1ab5e commit 8398d6b

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

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

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

103103
static final long SERVER_LATENCY = 75;
104104
static final int ITERATION_COUNT = 3;
105+
static final long CLIENT_SHUTDOWN_GRACE_DELAY = 1500; // milliseconds
105106
// a shared executor helps reduce the amount of threads created by the test
106107
static final Executor executor = new TestExecutor(Executors.newCachedThreadPool());
107108
static final ConcurrentMap<String, Throwable> FAILURES = new ConcurrentHashMap<>();
@@ -285,7 +286,7 @@ public void testAsLines(String uri, boolean sameClient)
285286
if (sameClient) continue;
286287
client = null;
287288
System.gc();
288-
var error = TRACKER.check(tracker, 500);
289+
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
289290
if (error != null) throw error;
290291
}
291292
}
@@ -327,7 +328,7 @@ public void testInputStream(String uri, boolean sameClient)
327328
if (sameClient) continue;
328329
client = null;
329330
System.gc();
330-
var error = TRACKER.check(tracker, 1);
331+
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
331332
if (error != null) throw error;
332333
}
333334
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public void teardown() throws Exception {
445445
sharedClient == null ? null : sharedClient.toString();
446446
sharedClient = null;
447447
Thread.sleep(100);
448-
AssertionError fail = TRACKER.check(500);
448+
AssertionError fail = TRACKER.check(1500);
449449
try {
450450
http1TestServer.stop();
451451
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)