Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions test/jdk/java/lang/invoke/ClassValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -209,7 +212,6 @@ private static void awaitThreads(Iterable<Thread> 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);
Expand Down Expand Up @@ -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<Object> cv = new ClassValue<>() {
@Override
Expand All @@ -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<Boolean> cv = new ClassValue<>() {
@Override
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -352,7 +355,6 @@ protected int[] computeValue(Class<?> type) {
}

@Test
@Timeout(value = 4, unit = TimeUnit.SECONDS)
void testRacyRemoveInCompute() {
ClassValue<Object> cv = new ClassValue<>() {
@Override
Expand Down Expand Up @@ -398,7 +400,6 @@ record One() {
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);
Expand Down Expand Up @@ -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);
Expand Down