Testing Workflow Completion For Non Retryable Errors

Hi Team,

I have a workflow with 4 activities and I have specified to not retry a particular exception in my activity options in the workflow.

However when I create the TestWorkflowExtension as below

 @RegisterExtension
        @JvmField
        val testWorkflowExtension: TestWorkflowExtension = TestWorkflowExtension.newBuilder()
            .setWorkerOptions(WorkerOptions { WorkflowImplementationOptions{
                setDefaultActivityOptions(ActivityOptions { RetryOptions{ setDoNotRetry(NoSuchElementException::class.java.name) } })}
            })
            .setWorkflowTypes(ExpenseCategoryWorkflowImpl::class.java)
            .setDoNotStart(true)
            .build()

and in my test when I throw this NoSuchElementException , the test doesn’t pass and workflow execution doesn’t say completed. Though I know this is how it behaves in real scenario from my manual tests.

 @Test
    fun `automate expense category workflow is successful`(
        testEnv: TestWorkflowEnvironment, worker: Worker, workflow: ExpenseCategoryWorkflow
    ) {
        val activity: ExpenseCategoryActivity = Mockito.mock(ExpenseCategoryActivity::class.java)
        whenever(activity.getCategoriesForExpense(getCategoryForExpenseInputDTO)).then{throw NoSuchElementException()}
        worker.registerActivitiesImplementations(activity)
        testEnv.start()
        assertDoesNotThrow {
            workflow.automateExpenseCategory(expenseInputDTO)
        }
        verify(activity).getCategoriesForExpense(getCategoryForExpenseInputDTO)
    }

what am I missing here? This is an extension of the questions asked in this thread Testing pattern for Temporal Workflow - Java

Would you file an issue to get the ability to specify WorkflowImplementationOptions through TestWorkflowExtension.Builder?

Thank you for the quick response Maxim. Could you give me the link to file this issue (will bookmark it) . Also to confirm, I am able to set the WorkflowImplementationOptions in the worker options in TestWorkflowExtension as you see in my code above, is this not taking effect?

Issues · temporalio/sdk-java · GitHub.

I don’t think WorkerOptions contain WorkflowImplementationOptions.

1 Like

I will file an issue. However, Is it possible to have the Workflow instance status to be Completed in this case where I expect an exception and do not retry it by throwing as an non retryable application failure error? It currently says failed as one would expect.I do have a work around for this but still thought will ask.

Thanks a lot for all the help. It has been really helpful.

Just to add, Junit4 TestWorkflowRule allows you to pass WorkflowImplementationOptions when you register your workflows, for example:

@Rule
  public TestWorkflowRule testWorkflowRule =
    TestWorkflowRule.newBuilder()
        .setWorkflowTypes(myWorkflowImplementationOptions, MyWorkflowImpl1.class, MyWorkflowImpl2)
        // ...
        .build();

(and yes TestWorkflowExtension.setWorkflowTypes does not, should be added imo too, opened issue here).

Thank you tihomir. I am good on this for now.