Skip to content

Bug: Tester does not detect pending activity futures after workflow completion #436

Description

@j-nowakowski

Issue

We recently were trying to create a unit test to reproduce an issue in live code where a workflow was completed while a pending future was inflight, expecting the error workflow completed, but there are still pending futures. However we found that we could not reproduce the error when the future was an activity. This prevents us from writing tests which validate that we don't leave pending futures on accident. This occurs regardless of if the activity is mocked or not.

Workflows version v1.3.0.

Reproduce:

Create this file:

package main

import (
	"context"
	"testing"
	"time"

	"github.com/cschleiden/go-workflows/tester"
	wf "github.com/cschleiden/go-workflows/workflow"
	"github.com/stretchr/testify/require"
)

func TestFoo(t *testing.T) {
	wft := tester.NewWorkflowTester[any](WF)
	// wft.OnActivity(Act, mock.Anything).Return(nil)
	wft.Execute(t.Context())
	require.True(t, wft.WorkflowFinished())
	_, err := wft.WorkflowResult()
	require.ErrorContains(t, err, "workflow completed, but there are still pending futures")
}

func WF(ctx wf.Context) error {
	wf.ExecuteActivity[any](ctx, wf.DefaultActivityOptions, Act)
	return nil
}

func Act(context.Context) error {
	time.Sleep(10 * time.Second)
	return nil
}

Run command:

go test <file>

Expected result: the test is successful. Instead, the test reports no error returned from wft.WorkflowResult().

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions