Errors in unit test


#1

Hello everyone, i need some help with camunda unit test.
I use springBoot and trying to make tests for a camunda proccess, i have some asynchronious calls with callbacks, and i mock it like that
ArgumentCaptor argument = ArgumentCaptor.forClass(UUID.class);
doAnswer((Answer) -> {
someService.someProcessCallback(argument.getValue(),
Object1);
return new ResponseEntity<>(HttpStatus.OK);
})
.when(someApi).someProcess(argument.capture(),
anyString(), any(Object2.class), eq(null), eq(null), eq(null));

Here the process code, witch makes errors:

public void someProcess(Object5 object5, String id) {
    UUID uuid= UUID.randomUUID();
    execution.setVariable("correct_uuid_variable", uuid.toString());

    someApi.someProcess(uuid, someUrl,
            createObject2(Id), null, null, null);

}
and callback:
@Async
public void someProcessCallback(UUID uuid, Object1 object1) {
runtimeService.createMessageCorrelation(“correct_process_message”)
.processInstanceVariableEquals(“correct_uuid_variable”, uuid.toString())
.correlate();
}
}
}
When proccess comes to callback it`s throws org.camunda.bpm.engine.MismatchingMessageCorrelationException

I starting proccess like this:
@Autowired
private RuntimeService runtimeService;
runtimeService.createProcessInstanceByKey(“someProcess”)
.setVariables(mapOfAllCorrectNeccessaryVariables);
someVerify();

I thoght that problem is in callbackMock, i thought it comes to early after starting api process, but
Thread.sleep befor sending callback - doesn`t solve the problem.


#2

MismatchingMessageCorrelationException is thrown when the message can be correlated to more than one event. Please check you deployed processes if they have more than once the same message.


#3

Thank you for answer, but if i correctly understand this part of log:
18:04:41.768 [ThreadPoolTaskExecutor-1] DEBUG o.c.b.e.i.p.e.E.selectMessageStartEventSubscriptionByName - <== Total: 0

It`sactually zero events in database, not more than one
And one more confusing thing - sometimes, once out of 10 test can pass without any problems


#4

Sorry, my mistake, you are right, the same exception is thrown when there’s not message event as well.
It seems your test is not stable in terms of available messages to correlate. You can share it (together with the resources, the processes) to have a look at it.


#5

Unfortunetly, i cant share it, its commercial.
I will try to find solution myself then. But if you have any advice - i will be glad to hear it,
Thank you, Yana


#6

Verify that the tests are independent from each other and each one cleanups the used resources (deployments, processes) after them.
Try to isolate the problematic tests when the failure occurs.
In case you are able to create a sample project where the error is reproducible, please share it.


#7

I thought about that before and deleted all tests except one, but it doesnt help. For some reson in sample project problem doesnt accurs, maybe i missing something


#8

Here some new updates. Its seems like this problem only accurs if there are included processes, they fails in included methods, but if you start the lowest level proccess without included proccess - it will not fail in same place of code, that why my sample project didnt reproduce the problem. I solve the problem by mocking sub proccess in some test with ProcessExpressions, but other problem accurs, now i depending with tests ordering, because i dont know how to reset this mocks. Maybe somebody will help me with reset?