Skip to content

Interceptors are skipped for mocked activities #1468

Open
@PatrikValo

Description

@PatrikValo

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

  1. Define interceptors in the test environment
  2. Mock non local activity with return values
  3. 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

fnName := m.name
// check if mock returns function which must match to the actual function.
if mockFn := m.getMockFn(mockRet); mockFn != nil {
// we found a mock function that matches to actual function, so call that mockFn
if m.isWorkflow {
executor := &workflowExecutor{workflowType: fnName, fn: mockFn}
return executor.Execute(ctx.(Context), input)
}
executor := &activityExecutor{name: fnName, fn: mockFn}
return executor.Execute(ctx.(context.Context), input)
}
return m.getMockValue(mockRet)

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions