Skip to content

Commit

Permalink
Test with JDK 23 (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Oct 10, 2024
1 parent e6fb0e5 commit c551093
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ jobs:
vm: 'openj9'
- version: 21
vm: 'openj9'
- version: 23
vm: 'hotspot'
steps:
# We use the cached working directory so that we don't have to recompile everything
- name: Download cached build working directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -185,15 +187,6 @@ public void enablingVirtualThreadSupportDoesNotThrow() {
@Test
@EnabledForJreRange(min = JRE.JAVA_21)
public void testVirtualThreadsExcludedByDefault() throws Exception {
if (System.getProperty("java.vm.name").toUpperCase().contains("J9")) {
// We exclude this test on OpenJ9, because it is flaky there
// It seems like sometimes OpenJ9 does not disable the mount/unmount listeners
// even though it didn't report an error
// While this can cause this test to fail, in practice this doesn't cause any problems
// because we never disable the support after enabling it in the real world
return;
}

ExecutorService exec =
(ExecutorService)
Executors.class.getMethod("newVirtualThreadPerTaskExecutor").invoke(null);
Expand All @@ -207,6 +200,9 @@ public void testVirtualThreadsExcludedByDefault() throws Exception {
.isNull();
})
.get();

exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
}

@Test
Expand Down Expand Up @@ -267,6 +263,26 @@ public void testVirtualThreadsStoragePropagatedWithMounts() throws Exception {
for (Future<?> future : threadResults) {
future.get(); // this will throw an ExecutionException if any assertions failed
}

// We need to properly wait for all virtual threads to be actually ended and unmounted
// otherwise we might not correctly remove the virtual-thread TLS attached to the carrier
// thread and leak it to other tests
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);

// Wait until all virtual threads are GCed, just to be sure
List<WeakReference<Thread>> threadsWeak =
virtualThreads.stream().map(WeakReference::new).collect(Collectors.toList());
virtualThreads.clear();
threadLatches.clear();
threadResults.clear();
await()
.atMost(Duration.ofSeconds(10))
.until(
() -> {
System.gc();
return threadsWeak.stream().allMatch(weakRef -> weakRef.get() == null);
});
}
}

Expand Down

0 comments on commit c551093

Please sign in to comment.