Hi,
Some background:
I’m creating a workflow with execution time limit (aka SLA). If the workflow is executed for too long, some clean-up activity needs to be executed before completing the workflow. I’m going to set ScheduleToCloseTimeout for each activity with remaining workflow time. Eventually, if either activity is terminated due to timeout or there is no remaining workflow time, workflow will execute the clean-up process (please advise if there is a better way to implement it)
Problem:
While trying to test workflow’s activity ScheduleToCloseTimeout, I found it doesn’t work.
In the example below, I’d expect use case “// delay 2 hours …” returns timeout error. Please let me know if I’m missing something.
func yourActivity(ctx context.Context) (string, error) {
return "result", nil
}
func (s *UnitTestSuite) Test_MockActivityWait() {
workflowFn := func(ctx workflow.Context) error {
ao := workflow.ActivityOptions{
ScheduleToCloseTimeout: 1 * time.Hour,
}
ctx = workflow.WithActivityOptions(ctx, ao)
var result string
err := workflow.ExecuteActivity(ctx, yourActivity).Get(ctx, &result)
return err
}
// no delay to the mock call, workflow should return no error
env := s.NewTestWorkflowEnvironment()
env.RegisterWorkflow(workflowFn)
env.RegisterActivity(yourActivity)
env.OnActivity(yourActivity, mock.Anything).Return("mock result1", nil)
env.ExecuteWorkflow(workflowFn)
s.True(env.IsWorkflowCompleted())
s.NoError(env.GetWorkflowError())
env.AssertExpectations(s.T())
// delay 2 hours, which is longer than the 1h timer, and workflow should return error.
env = s.NewTestWorkflowEnvironment()
env.RegisterActivity(yourActivity)
env.OnActivity(yourActivity, mock.Anything).After(time.Hour*2).Return("mock result12", nil)
env.ExecuteWorkflow(workflowFn)
s.True(env.IsWorkflowCompleted())
s.Error(env.GetWorkflowError())
env.AssertExpectations(s.T())
}