Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reassign runningWorkflows workflow ID in test environment #1163

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,10 @@ func (env *testWorkflowEnvironmentImpl) setStartWorkflowOptions(options StartWor
wf.WorkflowTaskTimeout = options.WorkflowTaskTimeout
}
if len(options.ID) > 0 {
// Reassign the ID in running Workflows so SignalWorkflowByID can find the workflow
originalID := wf.WorkflowExecution.ID
env.runningWorkflows[options.ID] = env.runningWorkflows[wf.WorkflowExecution.ID]
delete(env.runningWorkflows, originalID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally thinking maybe we wanted to also leave it in the map under the original ID, but if someone is referring to it by original ID in their tests even after setting w/ a new ID, I think they can be asked to fix their tests. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think it is a reasonable to ask they fix their test

wf.WorkflowExecution.ID = options.ID
}
if len(options.TaskQueue) > 0 {
Expand Down
24 changes: 23 additions & 1 deletion internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ package internal
import (
"context"
"errors"
"github.com/stretchr/testify/assert"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -227,6 +228,27 @@ func TestWorkflowIDInsideTestWorkflow(t *testing.T) {
require.Equal(t, "id is: my-workflow-id", str)
}

func TestWorkflowIDSignalWorkflowByID(t *testing.T) {
var suite WorkflowTestSuite
// Test SignalWorkflowByID works with custom ID
env := suite.NewTestWorkflowEnvironment()
env.RegisterDelayedCallback(func() {
err := env.SignalWorkflowByID("my-workflow-id", "signal", "payload")
require.NoError(t, err)
}, time.Second)

env.SetStartWorkflowOptions(StartWorkflowOptions{ID: "my-workflow-id"})
env.ExecuteWorkflow(func(ctx Context) (string, error) {
var result string
GetSignalChannel(ctx, "signal").Receive(ctx, &result)
return "id is: " + GetWorkflowInfo(ctx).WorkflowExecution.ID, nil
})
require.NoError(t, env.GetWorkflowError())
var str string
require.NoError(t, env.GetWorkflowResult(&str))
require.Equal(t, "id is: my-workflow-id", str)
}

func TestWorkflowStartTimeInsideTestWorkflow(t *testing.T) {
var suite WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
Expand Down
Loading