Describe the bug
When we have any @Scheduled jobs in our application eg. @Scheduled(every="24h") which just does its job and I have a unit test which just does nothing but do System out will eventually call my Scheduled job .
Expected behavior
Unit test should not call Scheduled Jobs of the main package.
Actual behavior
Calls every Scheduled Jobs available in Quarkus Application .
To Reproduce
Steps to reproduce the behavior:
<properties>
<quarkus.platform.version>1.9.1.Final</quarkus.platform.version>
</properties>
...
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-quartz</artifactId>
</dependency>
ScheduleJob at main package and MyTest at test packageScheduleJob.java@Slf4j
@ApplicationScoped
public class ScheduledJob {
@Scheduled(every="60s")
void saveData() {
log.debug("Runs every 60 seconds");
}
@Scheduled(every="24h")
void clearData() {
log.debug("Runs every 1 day");
}
}
MyTest.java
@Slf4j
@QuarkusTest
public class MyTest {
@Test
public void test1(){
log.debug("Hello From test");
}
}
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
uname -a or ver: Linux ngm-pc 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linuxjava -version: Java 11mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)/cc @mkouba
@privatejava You can disable the scheduler when running the tests via quarkus.scheduler.enabled=false: https://quarkus.io/guides/scheduler-reference#scheduled-methods-and-testing
I don't think we should disable the scheduler by default for @QuarkusTest.
How do we disable it for only unit test because I do not want it to run in my CI/CD pipeline. Right now all I do is mvn clean install and it runs it anyway. Do you want me to update application.properties for unit test by using env or maven property to control that quarkus.scheduler.enabled property ?
You can use Configuration Profiles, i.e. add %test.quarkus.scheduler.enabled=false in your application.properties. You can also use system properties, i.e. something like mvn clean install -Dquarkus.scheduler.enabled=false should work. Finally, you can even create a specific test profile to disable the scheduler for some specific tests.
Most helpful comment
You can use Configuration Profiles, i.e. add
%test.quarkus.scheduler.enabled=falsein yourapplication.properties. You can also use system properties, i.e. something likemvn clean install -Dquarkus.scheduler.enabled=falseshould work. Finally, you can even create a specific test profile to disable the scheduler for some specific tests.