How to test timeouts?

Hi!

Im trying to test activities timeouts, but i don’t understand how works RegisterDelayedCallback :

My Workflow

func ExamWorkflow(ctx workflow.Context, examID string) (string, error) {

	logger := workflow.GetLogger(ctx)

	logger.Info("Starting workflow for exam ", examID)

	// pass exam to AWAITING_EXAM status
	ao := workflow.ActivityOptions{
		ScheduleToStartTimeout: 1 * time.Minute,
		StartToCloseTimeout:    1 * time.Minute,
		HeartbeatTimeout:       1 * time.Minute,
		ScheduleToCloseTimeout: 1 * time.Minute,
	}
	ctxAe := workflow.WithActivityOptions(ctx, ao)
	var res string
	err := workflow.ExecuteActivity(ctxAe, AwaitingExamActivity, examID).Get(ctxAe, &res)
	if err != nil {
		logger.Error("failed awaiting exam %s : %s", examID, err)
		return "", err
	}

	err = workflow.ExecuteActivity(ctxAe, ExamInProgressActivity, examID).Get(ctxAe, &res)
	if err != nil {
		logger.Error("failed inprogress exam %s : %s", examID, err)
		return "", err
	}

	logger.Info("Finishing workflow for exam %s", examID)

	return "", nil
}

My Activities

func AwaitingExamActivity(ctx context.Context, examID string) (string, error) {

	log := activity.GetLogger(ctx)
	activityInfo := activity.GetInfo(ctx)
	taskToken := activityInfo.TaskToken

	ioutil.WriteFile("./token.txt", taskToken, 0644)

	log.Info("Estado espera", "Valor token", string(taskToken))
	log.Info("Puts exam " + examID + " in AWAITING_EXAM status and takes a number for attention")

	return "", activity.ErrResultPending

}

// ExamInProgressActivity - Puts exam in EXAM_IN_PROGRESS status.
func ExamInProgressActivity(ctx context.Context, examID string) error {

	log := activity.GetLogger(ctx)
	log.Info("Puts exam ", examID, " in EXAM_IN_PROGRESS status and takes a number for attention")

	activityInfo := activity.GetInfo(ctx)
	taskToken := activityInfo.TaskToken

	ioutil.WriteFile("./token_eip.txt", taskToken, 0644)

	return activity.ErrResultPending

}

Test

func (s *UnitTestSuite) Test_Workflow() {

	env := s.NewTestWorkflowEnvironment()

	env.RegisterDelayedCallback(func() {
		token, err := ioutil.ReadFile("./token.txt")
		if err != nil {
			log.Fatal(err)
		}
		log.Println("en espera")
		env.CompleteActivity(token, "", nil)
	}, 10*time.Minute)

	env.RegisterActivity(AwaitingExamActivity)

	env.RegisterDelayedCallback(func() {
		token, err := ioutil.ReadFile("./token_eip.txt")
		if err != nil {
			log.Fatal(err)
		}
		log.Println("en espera")
		env.CompleteActivity(token, "", nil)
	}, 10*time.Minute)

	env.RegisterActivity(ExamInProgressActivity)

	env.ExecuteWorkflow(ExamWorkflow, "45")

	s.True(env.IsWorkflowCompleted())
	err := env.GetWorkflowResult(nil)
	s.NoError(err)

}

The ActivityOptions has one minute in timeout for all their attributes and the callbacks has ten minutes, but the test finish ok.

Can anyone explain me why has this behaviour?

Thanks.

1 Like

It looks like a bug in the unit testing framework. Would you file an issue to get this looked at?

oh! thanks for the answer. Ok, i will report this case. Regards.