Scenario test with async job not execute

Hi,

I am trying to test my processes containing a sendTask with a savepoint async after. When I try to run the test using the camunda-platform-scenario in run normal mode, the test fails because it can’t find the job.

ERROR:

ENGINE-14026 No job found with id '6b06b63e-e9ce-11ed-b911-3e0f75024bfa'
org.camunda.bpm.engine.ProcessEngineException: ENGINE-14026 No job found with id '6b06b63e-e9ce-11ed-b911-3e0f75024bfa'

SCENARIO LOG:

13:32:15.337 [Test worker] INFO  org.camunda.bpm.scenario - * Starting scenario at 2023-05-03 13:32:15
13:32:15.444 [Test worker] DEBUG org.camunda.bpm.scenario - | Started   messageStartEvent  'Movable Created' (movable_created_event @ movable_process # 10406be6-e9d0-11ed-ab0a-3e0f75024bfa)
13:32:15.448 [Test worker] INFO  org.camunda.bpm.scenario - | Completed messageStartEvent  'Movable Created' (movable_created_event @ movable_process # 10406be6-e9d0-11ed-ab0a-3e0f75024bfa)
13:32:15.779 [Test worker] DEBUG org.camunda.bpm.scenario - | Executing async-continuation (transition-notify-listener-take$Flow_1ai3lee @ movable_process # 10406be6-e9d0-11ed-ab0a-3e0f75024bfa)
13:32:15.785 [Test worker] ERROR org.camunda.bpm.engine.context - ENGINE-16004 Exception while closing command context: ENGINE-14026 No job found with id '104bdd9f-e9d0-11ed-ab0a-3e0f75024bfa'
org.camunda.bpm.engine.ProcessEngineException: ENGINE-14026 No job found with id '104bdd9f-e9d0-11ed-ab0a-3e0f75024bfa'

However, when the test is run in debug mode, the process runs with the job.
scenario logger:

13:30:25.751 [Test worker] INFO  org.camunda.bpm.scenario - * Starting scenario at 2023-05-03 13:30:25
13:30:25.869 [Test worker] DEBUG org.camunda.bpm.scenario - | Started   messageStartEvent  'Movable Created' (movable_created_event @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:25.870 [Test worker] INFO  org.camunda.bpm.scenario - | Completed messageStartEvent  'Movable Created' (movable_created_event @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:32.540 [Test worker] DEBUG org.camunda.bpm.scenario - | Executing async-continuation (transition-notify-listener-take$Flow_1ai3lee @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:40.692 [Test worker] DEBUG org.camunda.bpm.scenario - | Started   exclusiveGateway   'Needs Cubing' (needs_cubing_gateway @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:40.853 [Test worker] INFO  org.camunda.bpm.scenario - | Completed exclusiveGateway   'Needs Cubing' (needs_cubing_gateway @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:41.028 [Test worker] DEBUG org.camunda.bpm.scenario - | Started   sendTask           'Create Unload' (create_unload_task @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:41.207 [Test worker] INFO  org.camunda.bpm.scenario - | Completed sendTask           'Create Unload' (create_unload_task @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:44.891 [Test worker] DEBUG org.camunda.bpm.scenario - | Executing async-continuation (transition-notify-listener-take$Flow_0bsh8kh @ movable_process # ceeeecaa-e9cf-11ed-878d-3e0f75024bfa)
13:30:47.889 [Test worker] INFO  org.camunda.bpm.scenario - * Finishing scenario at 2023-05-03 13:30:25

But it still gives the error:

ENGINE-03005 Execution of 'DELETE MessageEntity[38b44157-e9d0-11ed-a74a-3e0f75024bfa]' failed. Entity was updated by another transaction concurrently.
org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'DELETE MessageEntity[38b44157-e9d0-11ed-a74a-3e0f75024bfa]' failed. Entity was updated by another transaction concurrently.

How can I run the job to avoid this kind of error? Is there a way to mock the job? Or how can I insert a way for the test to wait for the job to finish?

Help me please :disappointed_relieved:

Hi,
I got it working using some settings:
Properties:

camunda.bpm.job-execution.enabled: false
@Mock
  private MyDelegateClass myDelegateClass;

@BeforeEach
  public void setup() {
    MockitoAnnotations.openMocks(this);
    Mocks.register("myDelegateClass", MyDelegateClass);
  }

When using external clients, I use stub for client:

stubFor(post(urlMatching("/myclient"))
            .willReturn(aResponse().withStatus(CREATED.value())));

And for tasks in process, is resolved it with mocks:

when(scenario.waitsAtReceiveTask("my_receive_task")).thenReturn(EventSubscriptionDelegate::receive);
    when(scenario.waitsAtMessageIntermediateCatchEvent("my_message_intermediate_event")).thenReturn(EventSubscriptionDelegate::receive);