cancel
Showing results for 
Search instead for 
Did you mean: 

Unit testing processes with async tasks

imbaczek
Champ in-the-making
Champ in-the-making
Hello,

This process' script1 task executes just fine in a unit test.

   <process id="my-process">

      <startEvent id="start" />
      <sequenceFlow id="flow1" sourceRef="start" targetRef="script1" />

      <scriptTask id="script1"
         name="log" scriptFormat="groovy" activiti:autoStoreVariables="false">
         <script>println("my-process-test-output")</script>
      </scriptTask>
      <sequenceFlow id="flow2" sourceRef="script1" targetRef="end" />

      <endEvent id="end" />

   </process>
   
But when I set activiti:async="true" in script1, the script doesn't execute, which is kind of expected. What to do to make it work? I need to unit test long-running scripts (waiting for external program output.)
2 REPLIES 2

martin_grofcik
Confirmed Champ
Confirmed Champ
Hello,

you can have a look on the following jUnit test

  @Deployment
  public void testAsycServiceNoListeners() { 
    INVOCATION = false;
    // start process
    runtimeService.startProcessInstanceByKey("asyncService");
    // now there should be one job in the database:
    assertEquals(1, managementService.createJobQuery().count());
    // the service was not invoked:
    assertFalse(INVOCATION);
   
    waitForJobExecutorToProcessAllJobs(10000L, 25L);
   
    // the service was invoked
    assertTrue(INVOCATION);   
    // and the job is done
    assertEquals(0, managementService.createJobQuery().count());      
  }

the process is:

  <process id="asyncService">
 
    <startEvent id="theStart" />
    <sequenceFlow id="flow1" sourceRef="theStart" targetRef="service" />
   
    <serviceTask id="service" activiti:class="org.activiti.engine.test.bpmn.async.AsyncService" activiti:async="true" />
   
    <sequenceFlow id="flow2" sourceRef="service" targetRef="theEnd" />
       
    <endEvent id="theEnd" />
   
  </process>

Regards
Martin

imbaczek
Champ in-the-making
Champ in-the-making
works great. thanks!