Quarkus: Quarkus Test runs Scheduled jobs as well .

Created on 2 Nov 2020  路  4Comments  路  Source: quarkusio/quarkus

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:

  1. Add Dependency for scheduler
<properties>
      <quarkus.platform.version>1.9.1.Final</quarkus.platform.version>
</properties>
...
<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-quartz</artifactId>
</dependency>
  1. Add Two classes one ScheduleJob at main package and MyTest at test package
    ScheduleJob.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");
    }
}
  1. Run the MyTest

Screenshots
(If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):

  • Output of 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/Linux
  • Output of java -version: Java 11
  • GraalVM version (if different from Java): openjdk version "11.0.7" 2020-04-14
    OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
    OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
  • Quarkus version or git rev: 1.9.1.FINAL
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
arescheduler kinquestion

Most helpful comment

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.

All 4 comments

/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.

Was this page helpful?
0 / 5 - 0 ratings