Hello,
In my test I’ve gotten a bug in the workflow code itself (not the activities), and the service just tried to run it over and over again… I would like to provide Workflow Options (at least in the test environment) to make sure such cases will fail the test instead of trying forever… but I have found no way to do that using the TestWorkflowExtension. Is there a way do to such config?
             
            
              
              
              
            
            
           
          
            
            
              Assuming you are currently registering your workflow impls via TestWorkflowExtension->setWorkflowTypes.
One thing you can do is for example:
@RegisterExtension
  public static final TestWorkflowExtension testWorkflowExtension =
      TestWorkflowExtension.newBuilder()
          .setDoNotStart(true)
          .build();
and then in your test method set fail workflow exceptions via WorkflowImplementationOptions, for example:
@Test
  public void myTestMethod(
      TestWorkflowEnvironment testEnv, Worker worker) {
    worker.registerWorkflowImplementationTypes(
            WorkflowImplementationOptions.newBuilder()
                    .setFailWorkflowExceptionTypes(NullPointerException.class)
                    .build(),
            TripBookingWorkflowImpl.class);
    worker.registerActivitiesImplementations(new MyActivitiesImpl());
    testEnv.start();
    // ...
     MyWorkflow workflow = testEnv
              .getWorkflowClient()
              .newWorkflowStub(
                  MyWorkflow.class,
                  WorkflowOptions.newBuilder()
                      .setWorkflowId("<workflow_id>");
                      .setTaskQueue(worker.getTaskQueue())
                      .build());
       // ...
}
If you want your workflow to fail on any exception type, you could set FailWorkflowExceptionTypes to Throwable.class.
Hope this helps.
             
            
              
              
              1 Like