# Child workflow test running indefinitely

**URL:** <https://community.temporal.io/t/child-workflow-test-running-indefinitely/17086>\
**Category:** Community Support\
**Tags:** java-sdk, testing\
**Created:** [April 8, 2025, 10:00am UTC](https://community.temporal.io/t/child-workflow-test-running-indefinitely/17086 "2025-04-08T10:00:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdswnt](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@kdswnt](https://community.temporal.io/u/kdswnt)\
**Post date:** [April 8, 2025, 10:00am UTC](https://community.temporal.io/t/child-workflow-test-running-indefinitely/17086/1 "2025-04-08T10:00:10Z")

</div>

I have a parent workflow that calls a child workflow `PaymentSettlementWorkflow`. I’m mocking `PaymentSettlementWorkflow` as per [HelloChildJUnit5Test.java](https://github.com/temporalio/samples-java/blob/7e00384d75bcd6640e3eac1dcc763e0327836d36/core/src/test/java/io/temporal/samples/hello/HelloChildJUnit5Test.java). Upon running the test is hanging indefinitely.  
This the how I’m mocking the child workflow.

```java
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

```java
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
      }

```

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [April 20, 2025, 4:31pm UTC](https://community.temporal.io/t/child-workflow-test-running-indefinitely/17086/2 "2025-04-20T16:31:30Z")

</div>

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:

```auto

@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.
