Child workflow test running indefinitely

I have a parent workflow that calls a child workflow PaymentSettlementWorkflow. I’m mocking PaymentSettlementWorkflow as per HelloChildJUnit5Test.java. Upon running the test is hanging indefinitely.
This the how I’m mocking the child workflow.

class ParentWorkflowImplTest {
  @RegisterExtension
  public static final TestWorkflowExtension testWorkflowExtension = TestWorkflowExtension.newBuilder()
          .registerWorkflowImplementationTypes(ParentWorkflowImpl.class)
          .setDoNotStart(true)
          .build();
  
  @Test
  void testSettlementFailed(TestWorkflowEnvironment testEnv, Worker worker, ParentWorkflowInterface workflow) {
    PaymentSettlementWorkflow paymentSettlementWorkflow = mock(PaymentSettlementWorkflow.class);
    when(paymentSettlementWorkflow.checkSettlementStatus(any())).thenReturn(PayinSettlementStatusType.FAILED);

    worker.registerWorkflowImplementationFactory(
            PaymentSettlementWorkflow.class,
            () -> paymentSettlementWorkflow
    );
    testEnv.start();

    ApplicationStatus applicationStatus = workflow.process(input);
    assertNotNull(applicationStatus);
    assertEquals(ApplicationStatusType.REJECTED, applicationStatus.status());
  }
}

This the parent workflow logic that I’m testing

ChildWorkflowOptions applicantWorkflowOptions = ChildWorkflowOptions.newBuilder()
              .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
              .setWorkflowId(workflowId)
              .setTaskQueue(WorkflowApplicationObserver.TASK_QUEUE)
              .build();

      PaymentSettlementWorkflow paymentSettlementWorkflow = Workflow.newChildWorkflowStub(PaymentSettlementWorkflow.class, applicantWorkflowOptions);
      PayinSettlementStatusType settlementStatus = paymentSettlementWorkflow.checkSettlementStatus(payin);
      if (PayinSettlementStatusType.FAILED.equals(settlementStatus)) {
        //handle failure
       //return Rejected status
      }

Looks like you are starting child on different task queue than where you are starting parent:
.setTaskQueue(WorkflowApplicationObserver.TASK_QUEUE)

When using test env then your test would hang as you dont have a worker registered on this child specific queue.

You could create a worker for this child-wf task queue, something like:


@Test
  void testSettlementFailed(TestWorkflowEnvironment testEnv, Worker worker, ParentWorkflowInterface workflow) {
    PaymentSettlementWorkflow paymentSettlementWorkflow = mock(PaymentSettlementWorkflow.class);
    when(paymentSettlementWorkflow.checkSettlementStatus(any())).thenReturn(PayinSettlementStatusType.FAILED);

   // worker is going to be for the test env task queue, not the child one
   // so we need to create a new worker for the child specific tq
   Worker childWorker =
        testEnv.newWorker(WorkflowApplicationObserver.TASK_QUEUE);
    childWorker.registerWorkflowImplementationFactory(
            PaymentSettlementWorkflow.class,
            () -> paymentSettlementWorkflow
    );
    testEnv.start();

    // ...
  }

If your WorkflowApplicationObserver.TASK_QUEUE is used for both the parent and child workflow, then there is no need to specify it in your ChildWorkflowOptions, and if you remove it there
there should be no need to create the extra worker.