英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论