diff --git a/test/jdk/java/lang/invoke/ClassValueTest.java b/test/jdk/java/lang/invoke/ClassValueTest.java index fa026955e2549..856653b3f92f2 100644 --- a/test/jdk/java/lang/invoke/ClassValueTest.java +++ b/test/jdk/java/lang/invoke/ClassValueTest.java @@ -176,11 +176,14 @@ public void testGetMany() { } 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 @@ private static void awaitThreads(Iterable threads) { * 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 @@ protected Integer computeValue(Class type) { * Tests that calling get() from computeValue() terminates. */ @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testGetInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -263,7 +264,6 @@ protected Object computeValue(Class type) { * Tests that calling remove() from computeValue() terminates. */ @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testRemoveInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -315,7 +315,10 @@ protected int[] computeValue(Class type) { 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 @@ protected int[] computeValue(Class type) { } @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testRacyRemoveInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -398,7 +400,6 @@ record One() { private static final ScopedValue 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 @@ protected Object computeValue(Class type) { } @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testNoObsoleteInstallation() throws InterruptedException { CountDownLatch slowComputationStart = new CountDownLatch(1); CountDownLatch slowComputationContinue = new CountDownLatch(1);