# Catching event with timer trigger in unit tests

**URL:** <https://forum.flowable.org/t/catching-event-with-timer-trigger-in-unit-tests/9651>\
**Category:** Flowable Engine\
**Created:** [August 16, 2022, 2:11pm UTC](https://forum.flowable.org/t/catching-event-with-timer-trigger-in-unit-tests/9651 "2022-08-16T14:11:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastiaanu](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/sebastiaanu/32/2907_2.png) [@Sebastiaanu](https://forum.flowable.org/u/Sebastiaanu)\
**Post date:** [August 16, 2022, 2:11pm UTC](https://forum.flowable.org/t/catching-event-with-timer-trigger-in-unit-tests/9651/1 "2022-08-16T14:11:30Z")

</div>

Hi,

In our BPM project, we need the process to wait before performing the next external worker call. The way I implemented this is as follows.  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/6/6f261b370134f39dfa7de396386850a3aaa44432.png)  
However I will need to unit test this, and just following the external worker flow will not work. I have tried looking for the answer in the JobTestHelper documentation, and came across the following (also referenced in another topic on this forum):

```auto
Job timer = managementService.createTimerJobQuery().singleResult();
        while (timer == null){
            timer = managementService.createTimerJobQuery().singleResult();
        }
        Job executableJob = managementService.moveTimerToExecutableJob(timer.getId());
        managementService.executeJob(executableJob.getId());

```

This implementation gives the following error

```auto
 HistoricActivityInstanceEntity [...] was updated by another transaction concurrently

```

my question: is this the correct way to implement the timer in my process, and if so, what is the correct way to implement the timer in my unit tests?

Best regards,  
Sebastiaan

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [August 17, 2022, 11:12am UTC](https://forum.flowable.org/t/catching-event-with-timer-trigger-in-unit-tests/9651/2 "2022-08-17T11:12:31Z")

</div>

Hi Sebastiaan,

One way is to trigger timer as you wrote.  
another to move in time (`engineConfiguration.getClock()`) after the timer due time and wait till the timer is not triggered automatically by engine (allow timer execution)

Regards  
Martin
