8298931: java/net/httpclient/CancelStreamedBodyTest.java fails with AssertionError due to Pending TCP connections: 1

Reviewed-by: jpai
This commit is contained in:
Daniel Fuchs 2022-12-20 11:05:38 +00:00
parent 36de61c460
commit 5df00d34fe
3 changed files with 31 additions and 10 deletions

@ -104,6 +104,7 @@ public class CancelStreamedBodyTest implements HttpServerAdapters {
static final long SERVER_LATENCY = 75;
static final int ITERATION_COUNT = 3;
static final long CLIENT_SHUTDOWN_GRACE_DELAY = 1500; // milliseconds
// a shared executor helps reduce the amount of threads created by the test
static final Executor executor = new TestExecutor(Executors.newCachedThreadPool());
static final ConcurrentMap<String, Throwable> FAILURES = new ConcurrentHashMap<>();
@ -287,7 +288,7 @@ public class CancelStreamedBodyTest implements HttpServerAdapters {
if (sameClient) continue;
client = null;
System.gc();
var error = TRACKER.check(tracker, 500);
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
if (error != null) throw error;
}
}
@ -329,7 +330,7 @@ public class CancelStreamedBodyTest implements HttpServerAdapters {
if (sameClient) continue;
client = null;
System.gc();
var error = TRACKER.check(tracker, 1);
var error = TRACKER.check(tracker, CLIENT_SHUTDOWN_GRACE_DELAY);
if (error != null) throw error;
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -447,7 +447,7 @@ public class ISO_8859_1_Test implements HttpServerAdapters {
sharedClient == null ? null : sharedClient.toString();
sharedClient = null;
Thread.sleep(100);
AssertionError fail = TRACKER.check(500);
AssertionError fail = TRACKER.check(1500);
try {
http1TestServer.stop();
https1TestServer.stop();

@ -214,12 +214,15 @@ public class ReferenceTracker {
long waitStart = System.nanoTime();
long waited = 0;
long toWait = Math.min(graceDelayMs, Math.max(delay, 1));
for (int i = 0; i < count; i++) {
int i = 0;
for (i = 0; i < count; i++) {
if (hasOutstanding.test(tracker)) {
System.gc();
try {
if (i == 0) {
System.out.println("Waiting for HTTP operations to terminate...");
System.out.println("\tgracedelay: " + graceDelayMs
+ " ms, iterations: " + count + ", wait/iteration: " + toWait + "ms");
}
waited += toWait;
Thread.sleep(toWait);
@ -250,7 +253,8 @@ public class ReferenceTracker {
printThreads(msg, System.err);
}
System.out.println("AssertionError: Found some " + description + " in "
+ tracker.getName() + " after " + duration + " ms, waited " + waited + " ms");
+ tracker.getName() + " after " + i + " iterations and " + duration
+ " ms, waited " + waited + " ms");
}
return fail;
}
@ -261,21 +265,34 @@ public class ReferenceTracker {
boolean printThreads) {
AssertionError fail = null;
graceDelayMs = Math.max(graceDelayMs, 100);
long waitStart = System.nanoTime();
long delay = Math.min(graceDelayMs, 10);
long toWait = Math.min(graceDelayMs, Math.max(delay, 1));
long waited = 0;
var count = delay > 0 ? graceDelayMs / delay : 1;
for (int i = 0; i < count; i++) {
int i = 0;
for (i = 0; i < count; i++) {
if (TRACKERS.stream().anyMatch(hasOutstanding)) {
System.gc();
try {
if (i == 0) {
System.out.println("Waiting for HTTP operations to terminate...");
System.out.println("\tgracedelay: " + graceDelayMs
+ " ms, iterations: " + count + ", wait/iteration: " + toWait + "ms");
}
Thread.sleep(Math.min(graceDelayMs, Math.max(delay, 1)));
waited += toWait;
Thread.sleep(toWait);
} catch (InterruptedException x) {
// OK
}
} else break;
} else {
System.out.println("No outstanding HTTP operations remaining after "
+ i + "/" + count + " iterations and " + waited + "/" + graceDelayMs
+ " ms, (wait/iteration " + toWait + " ms)");
break;
}
}
long duration = Duration.ofNanos(System.nanoTime() - waitStart).toMillis();
if (TRACKERS.stream().anyMatch(hasOutstanding)) {
StringBuilder warnings = diagnose(new StringBuilder(), hasOutstanding);
addSummary(warnings);
@ -284,7 +301,7 @@ public class ReferenceTracker {
}
} else {
System.out.println("PASSED: No " + description + " found in "
+ getTrackedClientCount() + " clients");
+ getTrackedClientCount() + " clients in " + duration + " ms");
}
if (fail != null) {
Predicate<Tracker> isAlive = Tracker::isSelectorAlive;
@ -292,6 +309,9 @@ public class ReferenceTracker {
printThreads("Some selector manager threads are still alive: ", System.out);
printThreads("Some selector manager threads are still alive: ", System.err);
}
System.out.println("AssertionError: Found some " + description + " in "
+ getTrackedClientCount() + " clients after " + i + " iterations and " + duration
+ " ms, waited " + waited + " ms");
}
return fail;
}