You don’t need to create workflow context explicitly. Workflow function is invoked by the worker when a workflow is executed. For starting workflow the standard context.Context is used.
We have some code in interceptors that are reading header values from workflow.Context and converting to our internal.Metadata in our internal key.
We can’t unit test them due to the unique nature of internal.Context creation, is it possible to request a public workflow.Context mock added in the Mocks?
I can’t think of too many use cases outside of Interceptors but since workflow.Context’s are exposed, in theory, should be something we should be able to UnitTest against if we are allowed to use them in our code.
Again it’s real small potato stuff, so we moved on.
Interceptors on my to do list, apologies for making it confusing.
We have code in the interceptors we are considering UnitTesting (it involves tracing/logging value propagation).
// ExecuteActivity middleware.
func (t *ContextOutboundCallsInterceptor) ExecuteActivity(
ctx workflow.Context,
activityType string,
args ...interface{}) workflow.Future {
rs := tcontext.GetNonSharedRootSpanFromTemporalContext(&ctx, t.Logger, activityType+"_Interceptor")
defer rs.End()
// before execution
result := t.Next.ExecuteActivity(ctx, activityType, args...)
// after execution
return result
}
tcontext.GetNonSharedRootSpanFromTemporalContext is the target of our UnitTest.
I am working around some design choices by our Logging authors in that they mutate context to ensure that values extracted initially from Context are all synchronized back inside the Context after creation (in case they were missing and default values were created).
In a similar situation, want to unit test a function with ctx workflow.Context in signature. Is there a way to build/mock internal.context just to do the unit testing without init worker/execute workflow?
Getting error: TaskState(Activity2) Error: A valid StartToClose or ScheduleToCl…+33 more, How do I specify activity option for testworkflowenvironment?
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: time.Minute,
StartToCloseTimeout: time.Minute,
}