JUNIT Test - Child workflow send signal to parent workflow

Hi, I’m writing JUNIT test case for asserting whether a signal has been sent from child workflow to parent workflow and parent workflow doesn’t wait for signal from child workflow. How can I write test for this scenario please suggest

1 Like

Hi @Avinash_Nayak
can you provide more info on “and parent workflow doesn’t wait for signal from child workflow”?

If the parent calls child async and completes before child sends the signal you
should be able to catch ApplicationFailure in child workflow, for example:

ParentWorkflow parent =
        Workflow.newExternalWorkflowStub(ParentWorkflow.class, Workflow.getInfo().getWorkflowId());
    try {
      // setName is parent signal handler
      parent.setName("child");
    } catch (ApplicationFailure e) {
      // e should have type SignalExternalWorkflowExecutionFailedCause.SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_EXTERNAL_WORKFLOW_EXECUTION_NOT_FOUND
    }

and you assert that this exception was thrown in child.

If you mean that parent workflow does not handle the signal, you could in test use maybe Mockito to verify its signal handler method was called.

Let us know what you mean by this specifically and provide your workflow, child workflow code to help clear this up more.