Description
Expected Behavior
I would expect that when I test a workflow and I mock an activity with return values like following
s.env.OnActivity(m.MyActivity, mock.Anything).Return(result, nil)
all executors defined in the test options
s.env.SetWorkerOptions(
worker.Options{
Interceptors: ...
},
)
are executed.
Actual Behavior
If I mock nonlocal activity with return values, interceptors are not executed. But for example if I mock the local activity in the tests with defined return values, interceptors are executed as expected. Also if I mock activities (local, nonlocal) with a function
s.env.OnActivity(m.MyActivity, mock.Anything).Return(func (ctx context.Context) (int, error) {
return result, nil
})
it works as expected and interceptors are executed.
Steps to Reproduce the Problem
- Define interceptors in the test environment
- Mock non local activity with return values
- Run workflow test
Specifications
- Version: 1.26
- Platform: I think problem is on all platforms
Thoughts
I think the problematic code lives in the internal/internal_workflow_testsuite.go
sdk-go/internal/internal_workflow_testsuite.go
Lines 1963 to 1975 in c69831e
If the mock is a function, we execute the activity executor that calls all interceptors internally. On other if we directly specify return values, we don't use the activity executor and
m.getMockValue(mockRet)
is called.
There is a workaround to provide a mock function, but it is not comfortable and readable if I have to define a function that just returns values on all places. So theoretically an easy fix could be to just wrap the mocked return values to a function at sdk level and unify the execution paths.