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

Quarkus Test runs Scheduled jobs as well . #13057

Closed
privatejava opened this issue Nov 2, 2020 · 4 comments
Closed

Quarkus Test runs Scheduled jobs as well . #13057

privatejava opened this issue Nov 2, 2020 · 4 comments
Labels
area/scheduler kind/question Further information is requested

Comments

@privatejava
Copy link

privatejava commented Nov 2, 2020

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 Arc - add basic BeanManager support #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)
@privatejava privatejava added the kind/bug Something isn't working label Nov 2, 2020
@quarkusbot
Copy link

/cc @mkouba

@mkouba
Copy link
Contributor

mkouba commented Nov 2, 2020

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

@mkouba mkouba closed this as completed Nov 2, 2020
@privatejava
Copy link
Author

privatejava commented Nov 2, 2020

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 ?

@mkouba
Copy link
Contributor

mkouba commented Nov 2, 2020

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.

@gsmet gsmet added kind/question Further information is requested and removed kind/bug Something isn't working labels Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scheduler kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants