From c16cc746064c858b6b871d0eef3c5e8479ff7bb0 Mon Sep 17 00:00:00 2001 From: Stones Date: Fri, 30 Oct 2026 09:58:22 -0500 Subject: [PATCH] Make DST-sensitive and timing-sensitive tests robust CallActivityTypeConversionTest and the CMMN TypeConversionTest asserted that a 10 day period is between 239h and 240h01m from now. A period is added in calendar days, so the span is 241h when it crosses a DST change, and the tests fail for the days before it. Compute the expected end with ZonedDateTime.plus(Period) and assert it is within a minute. BoundaryTimerEventTest asserted the timer due date is within 100 ms of a timestamp taken before the process start, which fails on a loaded machine. Allow 5 seconds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../flowable/cmmn/test/TypeConversionTest.java | 15 +++++++++++---- .../CallActivityTypeConversionTest.java | 7 +++++-- .../bpmn/event/timer/BoundaryTimerEventTest.java | 6 +++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/flowable-cmmn-engine-configurator/src/test/java/org/flowable/cmmn/test/TypeConversionTest.java b/modules/flowable-cmmn-engine-configurator/src/test/java/org/flowable/cmmn/test/TypeConversionTest.java index b4b661b1526..afed23dc8bb 100644 --- a/modules/flowable-cmmn-engine-configurator/src/test/java/org/flowable/cmmn/test/TypeConversionTest.java +++ b/modules/flowable-cmmn-engine-configurator/src/test/java/org/flowable/cmmn/test/TypeConversionTest.java @@ -15,7 +15,10 @@ import static org.assertj.core.api.Assertions.assertThat; import java.time.Duration; +import java.time.Instant; import java.time.LocalDate; +import java.time.Period; +import java.time.ZoneId; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -82,8 +85,10 @@ public void testProcessTaskTypeConversion() { Date now = new Date(); Object periodToDate = processEngine.getRuntimeService().getVariable(processInstance.getId(), "periodToDate"); assertThat(periodToDate).isInstanceOf(Date.class); - assertThat(Duration.between(now.toInstant(), ((Date) periodToDate).toInstant())) - .isBetween(Duration.ofDays(9).plusHours(23), Duration.ofDays(10).plusMinutes(1)); + // A period is added in calendar days, so across a DST change it is not exactly 240 hours + Instant expectedPeriodEnd = now.toInstant().atZone(ZoneId.systemDefault()).plus(Period.ofDays(10)).toInstant(); + assertThat(Duration.between(expectedPeriodEnd, ((Date) periodToDate).toInstant())) + .isBetween(Duration.ofMinutes(-1), Duration.ofMinutes(1)); Object durationToLocalDate = processEngine.getRuntimeService().getVariable(processInstance.getId(), "durationToLocalDate"); assertThat(durationToLocalDate).isInstanceOf(LocalDate.class); @@ -143,8 +148,10 @@ public void testCaseTaskTypeConversion() { Date now = new Date(); Object periodToDate = cmmnRuntimeService.getVariable(childCaseInstance.getId(), "periodToDate"); assertThat(periodToDate).isInstanceOf(Date.class); - assertThat(Duration.between(now.toInstant(), ((Date) periodToDate).toInstant())) - .isBetween(Duration.ofDays(9).plusHours(23), Duration.ofDays(10).plusMinutes(1)); + // A period is added in calendar days, so across a DST change it is not exactly 240 hours + Instant expectedPeriodEnd = now.toInstant().atZone(ZoneId.systemDefault()).plus(Period.ofDays(10)).toInstant(); + assertThat(Duration.between(expectedPeriodEnd, ((Date) periodToDate).toInstant())) + .isBetween(Duration.ofMinutes(-1), Duration.ofMinutes(1)); Object durationToLocalDate = cmmnRuntimeService.getVariable(childCaseInstance.getId(), "durationToLocalDate"); assertThat(durationToLocalDate).isInstanceOf(LocalDate.class); diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/callactivity/CallActivityTypeConversionTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/callactivity/CallActivityTypeConversionTest.java index abaa10168dd..235ade341bb 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/callactivity/CallActivityTypeConversionTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/callactivity/CallActivityTypeConversionTest.java @@ -17,6 +17,7 @@ import java.time.Duration; import java.time.Instant; import java.time.LocalDate; +import java.time.Period; import java.time.ZoneId; import java.util.Date; import java.util.HashMap; @@ -148,8 +149,10 @@ public void testInParameterTypeConversion() { Date now = new Date(); Object periodToDate = runtimeService.getVariable(childProcessInstance.getId(), "periodToDate"); assertThat(periodToDate).isInstanceOf(Date.class); - assertThat(Duration.between(now.toInstant(), ((Date) periodToDate).toInstant())) - .isBetween(Duration.ofDays(9).plusHours(23), Duration.ofDays(10).plusMinutes(1)); + // A period is added in calendar days, so across a DST change it is not exactly 240 hours + Instant expectedPeriodEnd = now.toInstant().atZone(ZoneId.systemDefault()).plus(Period.ofDays(10)).toInstant(); + assertThat(Duration.between(expectedPeriodEnd, ((Date) periodToDate).toInstant())) + .isBetween(Duration.ofMinutes(-1), Duration.ofMinutes(1)); Object durationToDate = runtimeService.getVariable(childProcessInstance.getId(), "durationToDate"); assertThat(durationToDate).isInstanceOf(Date.class); diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerEventTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerEventTest.java index 680d8c583ef..04aca8ba469 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerEventTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerEventTest.java @@ -544,7 +544,7 @@ public void testRescheduleBoundaryTimerOnUserTask() { Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(timerJob).isNotNull(); long diffInMilliseconds = Math.abs(startTimeInMillis - timerJob.getDuedate().getTime()); - assertThat(diffInMilliseconds).isLessThan(100); + assertThat(diffInMilliseconds).isLessThan(5000); // reschedule timer for two hours from now calendar = Calendar.getInstance(); @@ -742,7 +742,7 @@ public void testRescheduleRepeatBoundaryTimer() { Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(timerJob).isNotNull(); long diffInMilliseconds = Math.abs(startTimeInMillis - timerJob.getDuedate().getTime()); - assertThat(diffInMilliseconds).isLessThan(100); + assertThat(diffInMilliseconds).isLessThan(5000); // reschedule timer for two hours from now calendar = Calendar.getInstance(); @@ -806,7 +806,7 @@ public void testRescheduleBoundaryTimerOnSubProcess() { Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(timerJob).isNotNull(); long diffInMilliseconds = Math.abs(startTimeInMillis - timerJob.getDuedate().getTime()); - assertThat(diffInMilliseconds).isLessThan(100); + assertThat(diffInMilliseconds).isLessThan(5000); // reschedule timer for two hours from now calendar = Calendar.getInstance();