Skip to content

TestWorkflowEnvironment should surface errors and respect failure signal surfaced by underlying mock #1100

@qiuyijie-stripe

Description

@qiuyijie-stripe

Expected Behavior

Say I expect testWorkflow to invoke testActivity twice with certain arguments

env.OnActivity(testActivity, mock.Anything, testActivityParams{...}).Return(...).Times(2) 
req := testWorkflowRequest{...}

// Workflow actually invokes testActivity three times. Expect to see a test failure here due to the extra unexpected invocation.
env.ExecuteWorkflow(testWorkflow, req)

Actual Behavior

  • Test passes, but seeing the following error message from test output:
assert: mock: The method has been called over 2 times.
	Either do one more Mock.On(testActivity).Return(...), or remove extra call.
	This call was unexpected: ...
  • env.AssertExpectations doesn't catch the extra invocation, as it delegates to testify's mock.AssertExpectations, which only verifies that all configured invocations have been satisfied.
  • env.AssertNumberOfCalls doesn't catch the extra invocation either. Instead this happens:
env.OnActivity(testActivity, mock.Anything, testActivityParams{...}).Return(...).Times(2) 
req := testWorkflowRequest{...}

// Workflow actually invokes testActivity three times but test doesn't fail
env.ExecuteWorkflow(testWorkflow, req)

// Expect this assertion to fail but it passes
env.AssertNumberOfCalls("testActivity", 2)
// Expect this assertion to succeed but it fails
env.AssertNumberOfCalls("testActivity", 3)

I think this behavior has to do with the fact that env.AssertNumberOfCalls delegates to testify's mock.AssertNumberOfCalls. However, testify expects the test to have already failed early when the extra invocation occurred, and therefore does not increment its invocation counter. As a result, when the test unexpectedly continues on, the actual invocation counter remains at 2 even though there have been 3 calls to the activity.

testify's behavior seems correct and reasonable in this case. However, I'd expect TestWorkflowEnvironment to surface and respect the error and failure surfaced by testfify, and mark the test case as failed.

Steps to Reproduce the Problem

See above

Specifications

  • Version: v1.18.1
  • Platform: macOS Ventura 13.3.1

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