Unit testing process with event sub process

Hey!

We are currently implementing our processes in Camunda and everything is going great so far. We’ve gotten to the point that we’re using Camunda’s mockito to unit test the process flows, and also there so far so good.

However, we have a process that needs to end the process by sending a signal that does some compensating work and then cancels our order (process). When I run my flow tests everything is working as intended and I can see that the process passes the “Send signal” throw event. However, when I expected that my process to continue in the event sub process it ends the process (assertion) and the hasPassed() fails with any of the tasks within the event sub process.

A very naive example is shown below:

In my unit tests I can see that A is passed, along with the gateway and the signal event. After that the process is defined as finished and if I check if C is passed the test fails (as it never passed C)

Is there an easy way I’m not seeing that I can test the invocation of the event sub process as well?

Thanks a lot! :slight_smile:

Regards!
Egil Risvoll Sørensen

I seem to be able to test the event sub process itself by explicitly sending the signal event, but it does not seem to be sent/thrown from the throw event. Is this due to the job executor being disabled during testing?

This is working to test just the event sub process. I just want to test the process as a whole:

// Test the cancel signal sub process

ProcessInstanceAssert i = start(ResourceOrderBuilder.create().make());
processEngineRule.getRuntimeService().createSignalEvent(“Cancelled”).executionId(i.getActual().getProcessInstanceId()).send();
executeUntilStop();
i.isEnded().hasPassed(“CancelOrderSubProcess”);

The executeUntilStop is home made and just does execute(job()) for as long as possible

Can you post up you’re BPMN file - it’s possible that the signal is been thrown and not caught. Also a signal should not be used for your use case. a signal is a broadcast so the single being thrown would be picked up my every other instance waiting.

This isn’t the way i would suggest modeling compensation.
There’s a specific symbol for this event that would be better suited. I’ve created an example.

https://cawemo.com/shares/e0bc9f29-eeda-4389-9d03-5a9e241676cd

Thank you for your answer. Our main issue was that we tried to use the signal event as a goto-mechanism from inside a sub process to outside of it. The “compensation” (bad wording on my part) just meant running another sub process to cancel our order and then end the main process.

We solved this using normal flow with some gateways and link events (to keep diagram clean).

Thanks for you help! :slight_smile: