Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Allow to not invoke the test aot task with Gradle #1338

Closed
julb opened this issue Dec 3, 2021 · 10 comments
Closed

Allow to not invoke the test aot task with Gradle #1338

julb opened this issue Dec 3, 2021 · 10 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@julb
Copy link

julb commented Dec 3, 2021

Dear team,

I was thinking that I could be interesting to have an easy way to disable AOT for unit tests.
Indeed, for example, I'm currently building a Spring cloud function and I haveimplemented unit tests as indicated in Spring Cloud Function docs.
I will package this function with Native, but I don't want to tackle the native part for unit tests, the classic unit tests are fine.

In the gradle plugin, this section enables the aotTest for all tasks of type Test. Wouldn't it be good to do that section for GraalVM nativeTest task only ?

Also, aotMain seems to be run only for nativeCompile task so I think it would make sense to do the same for test.

What do you think ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 3, 2021
@julb julb changed the title Proposal: Ability to disable AOT for Unit tests Run aotTest only for GraalVM nativeTest command Dec 4, 2021
@olegz
Copy link
Contributor

olegz commented Dec 4, 2021

But isn't disabling AOT is as simple as setting VM option -DspringAot=false?

@julb
Copy link
Author

julb commented Dec 4, 2021

Hello,
Thanks for your feedback.

I tried with:

test {
    useJUnitPlatform()
    jvmArgs = ["-DspringAot=false"]
}

or using ./gradlew test -DspringAot=false and it has no effect.

The classpath for unit tests and the system properties are still modified by the plugin.

@sdeleuze sdeleuze changed the title Run aotTest only for GraalVM nativeTest command Support -DspringAot=false for tests Dec 5, 2021
@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 5, 2021

AOT mode for tests is useful for both JVM and native since it allows to ensure that the AOT flavor run fines on JVM (fast feedback loop) before going on native side (slower).

I think for now, AOT generation for test happen unconditionally (IMO not a major issue) and execution of tests in AOT mode (JVM or native) happen if generated test files are detected. I don't think we support -DspringAot=false for executing tests in regular mode but I think that could indeed be a good thing to support it.

For disabling native tests, Gradle Native Build Tools plugin allow to disable native tests via:

graalvmNative {
    testSupport = false
}

Maven Native Build Tools plugin allow to disable native test by removing the test-native execution and will support shortly doing that onthe command line via -DskipNativeTests, see graalvm/native-build-tools#179.

@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 5, 2021
@sdeleuze sdeleuze added this to the 0.11.1 milestone Dec 5, 2021
@julb
Copy link
Author

julb commented Dec 6, 2021

Thanks @sdeleuze for this feedback 👍

In the meantime, if someone else is interested by having a workaround, I did this for now in a subprojects block:

afterEvaluate {
  if (project.plugins.hasPlugin('org.springframework.experimental.aot')) {
    generateTestAot.onlyIf { false }
    test.configure { t ->
      t.systemProperties.remove('spring.test.context.default.CacheAwareContextLoaderDelegate')
    }
  }
}

@snicoll
Copy link
Contributor

snicoll commented Dec 6, 2021

For the record, this is only a problem with Gradle as far as I can see as Maven has two separate goals and you could decide to include them or not. If I understood correctly, generateTestAot is invoked with no way to disable it with Gradle? I wouldn't put pressure on fixing this but that looks a little odd to me.

IMO, this is also a different issue than having the plugin configured and choosing to run the tests without AOT.

@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 6, 2021

For the record, this is only a problem with Gradle

I am not sure I agree since with Maven test invoke AOT generation and someone could need to execute tests in regular mode without having to modify the pom.xml.

@snicoll
Copy link
Contributor

snicoll commented Dec 6, 2021

Yes but that's not the same problem. I understand there is no easy way to not invoke the test aot task with Gradle. IMO it is a more severe limitation than what you've described.

@bclozel
Copy link
Contributor

bclozel commented Dec 6, 2021

It is the way it is right now because we initially decided to make it the default.
But we could create a new aotTest task that depends on check.

@sdeleuze sdeleuze changed the title Support -DspringAot=false for tests Allow to not invoke the test aot task with Gradle Dec 7, 2021
@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 7, 2021

I renamed this issue to clarify it is about allowing to not invoke the test aot task with Gradle, and created #1356 about providing a way to use regular codepath for test execution.

@sdeleuze sdeleuze modified the milestones: 0.11.1, 0.11.2 Dec 17, 2021
@haroldlbrown
Copy link

For us, disabling AOT in Gradle for tests would also be beneficial.
We use MockBeans in our Spring integration tests. MockBean is currently not supported in AOT.
So disabling AOT would help us in not having to rewrite our Spring integration tests.

@sdeleuze sdeleuze self-assigned this Jan 12, 2022
sdeleuze added a commit to sdeleuze/spring-native that referenced this issue Jan 19, 2022
This commit:
 - Use Spring property check instead of classpath check to enable
   or not AOT test, that's more robust and prevent an IDEA bug
   (see spring-atticgh-1395)
 - Disable Maven AOT generation and execution with mvn test -DspringAot=false
 - Introduce a Gradle aotTest task for AOT generation + execution
   in order to allow executing regular tests with the test task

TODO find why ./gradlew aotTest does not behave like ./gradlew test:
 - Flag like --debug-jvm to enable debug from command line do
   not work
 - Customization via the DSL like
   test { testLogging { showStandardStreams = true } }
   are not applied

Closes spring-atticgh-1338
Closes spring-atticgh-1356
Closes spring-atticgh-1395
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement A general enhancement
Development

No branches or pull requests

7 participants