HTTP-Connector: Respects ClockUtil?

I am working with unit testing to generate some process history and using Wiremock and HTTP connector:

Consider something like:

....
                setTime(processStartTime)
                ProcessInstance registration = runtimeService().startProcessInstanceByKey('NewUserRegistration')
                forwardTime(30)
                complete(task(registration))
                assertThat(registration).isEnded()
                println 'process completed'
....

Where forwardTime() moves the Clock forward using something like:

...
Date forwardTime = ClockUtil.getCurrentTime() + duration.minutes
ClockUtil.setCurrentTime(forwardTime)
....

When time is moved forward, the duration in mills field of History Logs for HTTP Connector are all 0 mills. If i do not move time forward, durations are as expected.
When i move time forward in the case of the User Task Completion, the duration of the user task is as expected.

Is there something lacking with Connector usage?

So if you remove setTime() and forwardTime() run http-connector in a unit test you get expected results. If you move time/set a time http-connector/Connector does not appear to respect ClockUtil

Start Date is correct when using clockutil, but the end Date remains the same thus the duration issue i am guessing.

In fact it does. But the effect of ClockUtil#setCurrentTime is that the time is pinned to the provided timestamp. So durations of 0 seconds are expected behavior.

Oh… okok. is it possible to “move time forward”, rather than just pin it?

I’m afraid not. In Zeebe’s clock implementation we have this, but not in Camunda BPM.

well thats too bad… :frowning:

@thorben looking at the clockutil code; am I correct in understanding that I could override the Set and Get with my own java time clock which is a “ticking” clock ?

1 Like

It’s all static field and method access, so I’m not sure how you would override the methods without patching the engine or doing some classloader shenanigans.

edit: A pull request extending clock util for this use case is certainly welcome. Here’s Zeebe’s implementation: https://github.com/zeebe-io/zeebe/blob/develop/util/src/main/java/io/zeebe/util/sched/clock/ControlledActorClock.java