Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to JUnit 5 #467

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Switch to JUnit 5 #467

wants to merge 1 commit into from

Conversation

ivandev0
Copy link
Collaborator

@ivandev0 ivandev0 commented Feb 3, 2025

No description provided.

@ndkoval ndkoval requested a review from eupp February 4, 2025 10:58
@eupp
Copy link
Collaborator

eupp commented Feb 4, 2025

It seems that the JUnit 5 uses different approach to discover tests, which interferes in a non-obvious way with our class-loading hacks.

When I try to run tests locally from terminal, I got the following error:

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 3.
...
Caused by: java.lang.NoClassDefFoundError: sun/nio/ch/lincheck/EventTracker

So the problem seems to be because sun/nio/ch/lincheck/EventTracker class cannot be found.
This class belongs to the Lincheck's bootstrap package, and should be loaded by the bootstrap class loader.
In Lincheck, the bootstrap.jar is added to bootstrap class loader dynamically upon first installation of Lincheck jvm agent:

Normally, this should occur on the first Lincheck's test run.
And there are no sun/nio/ch/lincheck/EventTracker class (or any other class from bootstrap) usages outside the Lincheck's tests scope, so at the point when sun/nio/ch/lincheck/EventTracker is first loaded the bootstrap.jar should already be attached.

I suspect that JUnit 5 somehow uses reflection to discover tests in a way, that triggers earlier attempt to load sun/nio/ch/lincheck/EventTracker, before the Lincheck agent is installed and the bootstrap.jar is added to the classpath.

Adding the bootstrap.jar manually to the tests task seems to fix the problem locally for me.
That is, I've tried adding the following line to Test task:

jvmArgs("-Xbootclasspath/a:${file("${project(":bootstrap").buildDir}/libs/bootstrap.jar")}")

[Full snippet]

tasks.withType<Test> {
    useJUnitPlatform()
    javaLauncher.set(
        javaToolchains.launcherFor {
            val jdkToolchainVersion: String by project
            languageVersion.set(JavaLanguageVersion.of(jdkToolchainVersion))
        }
    )
    jvmArgs("-Xbootclasspath/a:${file("${project(":bootstrap").buildDir}/libs/bootstrap.jar")}") // added line
}

But I suspect we don't actually want to do this, and we need another solution for this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants