Skip to content

Starting a child workflow in tests leaks goroutines #2090

@mbark

Description

@mbark

Expected Behavior

If a child workflow is started and terminates during the test no go routine should be left once the test completes.

Actual Behavior

A go routine is left running from executeChildWorkflowWithDelay which doesn't seem to terminate.

Steps to Reproduce the Problem

  1. Create a test that runs a Workflow that starts a ChildWorkflow.
  2. Use defer goleak.VerifyNone(s.T())

I've added a repo to illustrate how to reproduce the issue, see the file do_test.go:

type TestSuite struct {
	suite.Suite
	testsuite.WorkflowTestSuite
}

func Test(t *testing.T) {
	suite.Run(t, new(TestSuite))
}

func ChildWorkflow(ctx workflow.Context) error {
	return workflow.Sleep(ctx, 24*time.Hour)
}

func ParentWorkflow(ctx workflow.Context) error {
	return workflow.ExecuteChildWorkflow(ctx, "ChildWorkflow", nil).Get(ctx, nil)
}

func (s *TestSuite) TestChildWorkflow() {
	defer goleak.VerifyNone(s.T())
	env := s.NewTestWorkflowEnvironment()
	env.RegisterWorkflow(ChildWorkflow)
	env.RegisterWorkflow(ParentWorkflow)

	env.ExecuteWorkflow(ParentWorkflow)
	err := env.GetWorkflowError()
	s.Require().NoError(err)

	env.AssertExpectations(s.T())
}

Specifications

  • Version: v1.37.0
  • Platform: -

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions