From 2581f58c6c1e009577a7f5848ca5f164ed223577 Mon Sep 17 00:00:00 2001 From: psavidis <69160690+psavidis@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:45:15 +0200 Subject: [PATCH] fix(quarkus-extesion/engine): Fix Flaky Quarkus Test Problem Description: - ManagedJobExecutorTest#shouldExecuteJob was failing sporadically on CI due to the asynchronous execution of scheduled jobs. The synchronous execution of the test would query for the existence of the job. Sometimes, the job would be already completed by the time the Query API would make assertions on its existence and that would lead into failures. Solution: - Turn off the job scheduler before filing any job executions Related-to: #3940 --- .../engine/test/ManagedJobExecutorTest.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/quarkus-extension/engine/deployment/src/test/java/org/camunda/bpm/quarkus/engine/test/ManagedJobExecutorTest.java b/quarkus-extension/engine/deployment/src/test/java/org/camunda/bpm/quarkus/engine/test/ManagedJobExecutorTest.java index 5abfed594c4..4efc62bc5cd 100644 --- a/quarkus-extension/engine/deployment/src/test/java/org/camunda/bpm/quarkus/engine/test/ManagedJobExecutorTest.java +++ b/quarkus-extension/engine/deployment/src/test/java/org/camunda/bpm/quarkus/engine/test/ManagedJobExecutorTest.java @@ -16,13 +16,18 @@ */ package org.camunda.bpm.quarkus.engine.test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.camunda.bpm.engine.impl.test.TestHelper.waitForJobExecutorToProcessAllJobs; + import io.quarkus.test.QuarkusUnitTest; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; import org.camunda.bpm.engine.ManagementService; import org.camunda.bpm.engine.ProcessEngine; import org.camunda.bpm.engine.RuntimeService; import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.camunda.bpm.engine.impl.jobexecutor.JobExecutor; -import org.camunda.bpm.engine.impl.test.TestHelper; import org.camunda.bpm.engine.runtime.ProcessInstance; import org.camunda.bpm.engine.test.Deployment; import org.camunda.bpm.quarkus.engine.extension.QuarkusProcessEngineConfiguration; @@ -35,12 +40,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.Produces; -import jakarta.inject.Inject; - -import static org.assertj.core.api.Assertions.assertThat; - public class ManagedJobExecutorTest { @RegisterExtension @@ -129,6 +128,7 @@ public void shouldNotReuseManagedExecutor() { @Deployment public void shouldExecuteJob() { // given + processEngineConfiguration.getJobExecutor().shutdown(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncTaskProcess"); // when @@ -137,14 +137,16 @@ public void shouldExecuteJob() { .processInstanceId(processInstance.getId()) .count(); - TestHelper.waitForJobExecutorToProcessAllJobs(processEngineConfiguration, 5000l, 25l); - // then assertThat(jobCount).isOne(); + + waitForJobExecutorToProcessAllJobs(processEngineConfiguration, 5000L, 25L); + jobCount = managementService .createJobQuery() .processInstanceId(processInstance.getId()) .count(); + assertThat(jobCount).isZero(); }