8357165: test java/lang/invoke/ClassValueTest.java fails intermittently

Reviewed-by: jpai
This commit is contained in:
Chen Liang 2025-05-22 14:24:59 +00:00
parent 428d33ef3c
commit 12efc1fe33

View File

@ -176,11 +176,14 @@ final class ClassValueTest {
}
private static final long COMPUTE_TIME_MILLIS = 100;
private static final Duration TIMEOUT = Duration.of(2, ChronoUnit.SECONDS);
// Adjust this timeout to fail faster for test stalls
private static final Duration TIMEOUT = Duration.ofNanos((long) (
Duration.of(1, ChronoUnit.MINUTES).toNanos()
* Double.parseDouble(System.getProperty("test.timeout.factor", "1.0"))));
private static void await(CountDownLatch latch) {
try {
if (!latch.await(2L, TimeUnit.SECONDS)) {
if (!latch.await(TIMEOUT.toNanos(), TimeUnit.NANOSECONDS)) {
fail("No signal received");
}
} catch (InterruptedException e) {
@ -209,7 +212,6 @@ final class ClassValueTest {
* Uses junit to do basic stress.
*/
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testRemoveStale() throws InterruptedException {
CountDownLatch oldInputUsed = new CountDownLatch(1);
CountDownLatch inputUpdated = new CountDownLatch(1);
@ -241,7 +243,6 @@ final class ClassValueTest {
* Tests that calling get() from computeValue() terminates.
*/
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testGetInCompute() {
ClassValue<Object> cv = new ClassValue<>() {
@Override
@ -263,7 +264,6 @@ final class ClassValueTest {
* Tests that calling remove() from computeValue() terminates.
*/
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testRemoveInCompute() {
ClassValue<Boolean> cv = new ClassValue<>() {
@Override
@ -315,7 +315,10 @@ final class ClassValueTest {
WeakReference<?> ref = new WeakReference<>(cv.get(int.class));
cv = null; // Remove reference for interpreter
if (!ForceGC.wait(() -> ref.refersTo(null))) {
if (!ForceGC.wait(() -> {
CV1.get(int.class); // flush the weak maps
return ref.refersTo(null);
})) {
fail("Timeout");
}
}
@ -352,7 +355,6 @@ final class ClassValueTest {
}
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testRacyRemoveInCompute() {
ClassValue<Object> cv = new ClassValue<>() {
@Override
@ -398,7 +400,6 @@ final class ClassValueTest {
private static final ScopedValue<Integer> THREAD_ID = ScopedValue.newInstance();
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testNoRecomputeOnUnrelatedRemoval() throws InterruptedException {
CountDownLatch t1Started = new CountDownLatch(1);
CountDownLatch removeTamper = new CountDownLatch(1);
@ -443,7 +444,6 @@ final class ClassValueTest {
}
@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testNoObsoleteInstallation() throws InterruptedException {
CountDownLatch slowComputationStart = new CountDownLatch(1);
CountDownLatch slowComputationContinue = new CountDownLatch(1);