temporal error when writing test for workflow that calls child workflow: "unable to find workflow type"

huangapple go评论94阅读模式
英文:

temporal error when writing test for workflow that calls child workflow: "unable to find workflow type"

问题

我正在使用golang SDK来编写Temporal的测试。我正在为我的LoadCreateWorkflow工作流编写一个测试。它包含一个活动,并启动一个名为LoadLifecycleWorkflow的子工作流。

在编写单元测试时,我模拟了活动和子工作流LoadLifecycleWorkflow

	s.env.OnActivity(CreateLoadActivity, mock.Anything, mock.Anything).Return(nil, nil).Once()
    s.env.OnWorkflow(LoadLifecycleWorkflow, mock.Anything).Return(nil)
	s.env.ExecuteWorkflow(LoadCreateWorkflow, wfParams)

(这里的s.env是单元测试的TestWorkflowEnvironment

import (
    ...
	"go.temporal.io/sdk/testsuite"
)

type UnitTestSuite struct {
	suite.Suite
	testsuite.WorkflowTestSuite

	env *testsuite.TestWorkflowEnvironment
}

func (s *UnitTestSuite) SetupTest() {
	s.env = s.NewTestWorkflowEnvironment()
}

运行测试时,我遇到了一个错误:panic: unable to find workflow type: LoadLifecycleWorkflow. Supported types: [LoadCreateWorkflow]

在我的工作流模块的init函数中,我注册了LoadCreateWorkflow和子工作流:

worker.RegisterWorkflow(LoadCreateWorkflow)
worker.RegisterActivity(CreateLoadActivity)
worker.RegisterWorkflow(LoadLifecycleWorkflow)

为什么会出现LoadLifecycleWorkflow未注册的错误,我该如何修复它?

英文:

I'm using the golang SDK for temporal. I'm writing a test for my workflow LoadCreateWorkflow. It has one activity and also kicks off a child workflow LoadLifecycleWorkflow.

When writing a unit test for it, I mock out the activity and child workflow LoadLifecycleWorkflow:

	s.env.OnActivity(CreateLoadActivity, mock.Anything, mock.Anything).Return(nil, nil).Once()
    s.env.OnWorkflow(LoadLifecycleWorkflow, mock.Anything).Return(nil)
	s.env.ExecuteWorkflow(LoadCreateWorkflow, wfParams)

(here s.env is the unit test's TestWorkflowEnvironment):

import (
    ...
	"go.temporal.io/sdk/testsuite"
)

type UnitTestSuite struct {
	suite.Suite
	testsuite.WorkflowTestSuite

	env *testsuite.TestWorkflowEnvironment
}

func (s *UnitTestSuite) SetupTest() {
	s.env = s.NewTestWorkflowEnvironment()
}

When running my test I get an error: panic: unable to find workflow type: LoadLifecycleWorkflow. Supported types: [LoadCreateWorkflow]

In my workflow module's init function I register both it and the child workflow:

worker.RegisterWorkflow(LoadCreateWorkflow)
worker.RegisterActivity(CreateLoadActivity)
worker.RegisterWorkflow(LoadLifecycleWorkflow)

Why do I get an error that my LoadLifecycleWorkflow is not registered and how do I fix it?

答案1

得分: 4

子工作流必须在Temporal的TestWorkflowEnvironment中注册:

s.env.RegisterWorkflow(LoadLifecycleWorkflow)

测试工作流环境是一个专门用于编写测试的不同环境,因此您在测试中期望您的工作流调用的任何子工作流都应该在此注册。

英文:

The child workflow must be registered to the temporal TestWorkflowEnvironment:

s.env.RegisterWorkflow(LoadLifecycleWorkflow)

The test workflow environment is a different environment that is just used for writing tests, so any child workflows you expect your workflow to call in your test should be registered to this.

huangapple
  • 本文由 发表于 2021年10月14日 04:51:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/69562169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定