Skip to content

Commit d2ee616

Browse files
committed
Fix flaky test failures on Kafka, DB2 and SQL Server
- TestEventConsumer: use CopyOnWriteArrayList instead of ArrayList to fix ConcurrentModificationException when Kafka listener threads add events while test assertions stream over the list - ProcessDefinitionSuspensionTest: use waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs instead of waitForJobExecutorToProcessAllJobs so the wait does not exit before timer jobs are acquired on slow databases like DB2 - ExternalWorkerServiceTaskTest (BPMN + CMMN): replace isEqualToIgnoringMillis with isCloseTo(date, 1000) to handle SQL Server datetime rounding across second boundaries
1 parent 07aaff9 commit d2ee616

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/externalworker/ExternalWorkerServiceTaskTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ public void testCaseInstanceIsCorrectlyLocked() {
977977
.singleResult();
978978

979979
assertThat(caseInstance.getLockOwner()).isEqualTo("worker1");
980-
assertThat(caseInstance.getLockTime()).isEqualToIgnoringMillis(acquiredJob.getLockExpirationTime());
980+
assertThat(caseInstance.getLockTime()).isCloseTo(acquiredJob.getLockExpirationTime(), 1000);
981981

982982
cmmnEngineConfiguration.getCommandExecutor().execute(new ClearCaseInstanceLockTimesCmd(
983983
cmmnEngineConfiguration.getAsyncExecutor().getLockOwner(), cmmnEngineConfiguration));
@@ -988,7 +988,7 @@ public void testCaseInstanceIsCorrectlyLocked() {
988988
.singleResult();
989989

990990
assertThat(caseInstance.getLockOwner()).isEqualTo("worker1");
991-
assertThat(caseInstance.getLockTime()).isEqualToIgnoringMillis(acquiredJob.getLockExpirationTime());
991+
assertThat(caseInstance.getLockTime()).isCloseTo(acquiredJob.getLockExpirationTime(), 1000);
992992

993993
cmmnEngineConfiguration.getCommandExecutor().execute(new ClearCaseInstanceLockTimesCmd("worker1", cmmnEngineConfiguration));
994994

modules/flowable-engine/src/test/java/org/flowable/engine/test/api/repository/ProcessDefinitionSuspensionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void testJobIsExecutedOnProcessDefinitionSuspend() {
244244

245245
// The jobs should simply be executed
246246
processEngineConfiguration.getClock().setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes
247-
waitForJobExecutorToProcessAllJobs(2000L, 100L);
247+
waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000L, 100L);
248248
assertThat(managementService.createJobQuery().count()).isZero();
249249
assertThat(managementService.createTimerJobQuery().count()).isZero();
250250
}
@@ -273,7 +273,7 @@ public void testDelayedSuspendProcessDefinition() {
273273
// Move clock 8 days further and let job executor run
274274
long eightDaysSinceStartTime = oneWeekFromStartTime + (24 * 60 * 60 * 1000);
275275
processEngineConfiguration.getClock().setCurrentTime(new Date(eightDaysSinceStartTime));
276-
waitForJobExecutorToProcessAllJobs(7000L, 200L);
276+
waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(7000L, 200L);
277277

278278
// verify job is now removed
279279
assertThat(managementService.createJobQuery().processDefinitionId(processDefinition.getId()).count()).isZero();
@@ -329,7 +329,7 @@ public void testDelayedSuspendProcessDefinitionIncludingProcessInstances() {
329329
// Move clock 9 days further and let job executor run
330330
long eightDaysSinceStartTime = oneWeekFromStartTime + (2 * 24 * 60 * 60 * 1000);
331331
processEngineConfiguration.getClock().setCurrentTime(new Date(eightDaysSinceStartTime));
332-
waitForJobExecutorToProcessAllJobs(7000L, 50L);
332+
waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(7000L, 50L);
333333

334334
// Try to start process instance. It should fail now.
335335
assertThatThrownBy(() -> runtimeService.startProcessInstanceById(processDefinition.getId()))
@@ -380,7 +380,7 @@ public void testDelayedActivateProcessDefinition() {
380380
// Move clock two days and let job executor run
381381
long twoDaysFromStart = startTime.getTime() + (2 * 24 * 60 * 60 * 1000);
382382
processEngineConfiguration.getClock().setCurrentTime(new Date(twoDaysFromStart));
383-
waitForJobExecutorToProcessAllJobs(7000L, 50L);
383+
waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(7000L, 50L);
384384

385385
// Starting a process instance should now succeed
386386
runtimeService.startProcessInstanceById(processDefinition.getId());

modules/flowable-engine/src/test/java/org/flowable/engine/test/externalworker/ExternalWorkerServiceTaskTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ void testProcessInstanceIsCorrectlyLocked() {
994994
.singleResult();
995995

996996
assertThat(processInstance.getLockOwner()).isEqualTo("worker1");
997-
assertThat(processInstance.getLockTime()).isEqualToIgnoringMillis(acquiredJob.getLockExpirationTime());
997+
assertThat(processInstance.getLockTime()).isCloseTo(acquiredJob.getLockExpirationTime(), 1000);
998998

999999
managementService.executeCommand(new ClearProcessInstanceLockTimesCmd(processEngineConfiguration.getAsyncExecutor().getLockOwner()));
10001000

@@ -1004,7 +1004,7 @@ void testProcessInstanceIsCorrectlyLocked() {
10041004
.singleResult();
10051005

10061006
assertThat(processInstance.getLockOwner()).isEqualTo("worker1");
1007-
assertThat(processInstance.getLockTime()).isEqualToIgnoringMillis(acquiredJob.getLockExpirationTime());
1007+
assertThat(processInstance.getLockTime()).isCloseTo(acquiredJob.getLockExpirationTime(), 1000);
10081008

10091009
managementService.executeCommand(new ClearProcessInstanceLockTimesCmd("worker1"));
10101010

modules/flowable-event-registry-spring/src/test/java/org/flowable/eventregistry/spring/test/TestEventConsumer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*/
1313
package org.flowable.eventregistry.spring.test;
1414

15-
import java.util.ArrayList;
1615
import java.util.List;
16+
import java.util.concurrent.CopyOnWriteArrayList;
1717
import java.util.Objects;
1818
import java.util.function.Consumer;
1919
import java.util.stream.Collectors;
@@ -31,7 +31,7 @@
3131
*/
3232
public class TestEventConsumer implements EventRegistryEventConsumer {
3333

34-
protected final List<EventRegistryEvent> events = new ArrayList<>();
34+
protected final List<EventRegistryEvent> events = new CopyOnWriteArrayList<>();
3535
protected Consumer<EventRegistryEvent> eventConsumer = event -> {};
3636

3737
@Override

0 commit comments

Comments
 (0)