The boundaryTimer not working

using a boundaryTimer which the timeDuration set to ‘PT5S’, i think the process will going to ‘nextTask’ after 5 seconds.

<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="firstTask" name="firstTask" activiti:dueDate="${finishTime}"></userTask>
<sequenceFlow id="flow3" sourceRef="startevent1" targetRef="firstTask"></sequenceFlow>
<userTask id="nextTask" name="nextTask" activiti:assignee="zn1"></userTask>
<sequenceFlow id="flow6" sourceRef="nextTask" targetRef="endevent1"></sequenceFlow>
<boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="firstTask" cancelActivity="true">
  <timerEventDefinition>
    <timeDuration>PT5S</timeDuration>
  </timerEventDefinition>
</boundaryEvent>
<sequenceFlow id="flow7" sourceRef="boundarytimer1" targetRef="nextTask"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="firstTask" targetRef="endevent1"></sequenceFlow>

write the test code:
@Test
@Deployment(resources = { “processes/timerProcess.bpmn” })
public void testLoop() throws InterruptedException {
DateTime dt = new DateTime();
Map<String, Object> vars = new HashMap<>();
vars.put(“finishTime”, dt.plusSeconds(5).toDate()); //
ProcessInstance ins = runtimeService.startProcessInstanceByKey(“timerProcess”, “1”, vars);
List ids = runtimeService.getActiveActivityIds(ins.getId());
assertEquals(“firstTask,boundarytimer1”, String.join(“,”, ids));

	Task t = taskService.createTaskQuery().processInstanceId(ins.getId()).singleResult();
	System.out.println(t.getName());
	assertEquals(t.getName(), "firstTask");
	
	Thread.sleep(6000l);   // sleeping 6 seconds
	t = taskService.createTaskQuery().processInstanceId(ins.getId()).singleResult();
	assertEquals(t.getName(), "nextTask");   // here will be failed, the real value is 'firstTask'
}

the test going failed, any help will be appreciated.

Do you have the async executor activated? No timer jobs will be picked up if it isn’t.

In tests, it’s not easy to used Thread.sleep. You can use managementService#moveTimerToExecutableJob and #executeJob for that.

Hi @sendreams

If you don’t want to manually move the timer job to an executable job you can also use the helper function: JobTestHelper.waitForJobExecutorToProcessAllJobs(…)
This allows you to wait for a certain time period until all jobs are executed.

Please have in mind that by default Flowable is polling every 10seconds for new timer jobs which need to be executed. In your use case that means it can take up to 16s until the task “nextTask” is created.

For testing purposes you can change it to less than 10s by changing the following property:
flowable.process.async.executor.default-timer-job-acquire-wait-time-in-millis

Regards,
Simon