Skip to content

Commit f1b2fc7

Browse files
authored
#936 followup: remove breaking test framework change, add integration test (#948)
1 parent 781a033 commit f1b2fc7

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (env *testWorkflowEnvironmentImpl) executeActivity(
537537
func (env *testWorkflowEnvironmentImpl) executeLocalActivity(
538538
activityFn interface{},
539539
args ...interface{},
540-
) (val Value, result *localActivityResult, err error) {
540+
) (val Value, err error) {
541541
params := executeLocalActivityParams{
542542
localActivityOptions: localActivityOptions{
543543
ScheduleToCloseTimeoutSeconds: common.Int32Ceil(env.testTimeout.Seconds()),
@@ -559,11 +559,11 @@ func (env *testWorkflowEnvironmentImpl) executeLocalActivity(
559559
tracer: opentracing.NoopTracer{},
560560
}
561561

562-
result = taskHandler.executeLocalActivityTask(task)
562+
result := taskHandler.executeLocalActivityTask(task)
563563
if result.err != nil {
564-
return nil, nil, result.err
564+
return nil, result.err
565565
}
566-
return newEncodedValue(result.result, env.GetDataConverter()), result, nil
566+
return newEncodedValue(result.result, env.GetDataConverter()), nil
567567
}
568568

569569
func (env *testWorkflowEnvironmentImpl) startDecisionTask() {

internal/internal_workflow_testsuite_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,11 +1616,8 @@ func (s *WorkflowTestSuiteUnitTest) Test_LocalActivity() {
16161616
}
16171617

16181618
env := s.NewTestActivityEnvironment()
1619-
result, localActivity, err := env.ExecuteLocalActivity(localActivityFn, "local_activity")
1619+
result, err := env.ExecuteLocalActivity(localActivityFn, "local_activity")
16201620
s.NoError(err)
1621-
s.Equal(WorkflowType{Name: workflowTypeNotSpecified}, localActivity.task.params.WorkflowInfo.WorkflowType)
1622-
s.Equal(defaultTestDomain, localActivity.task.params.WorkflowInfo.Domain)
1623-
s.Equal(defaultTestTaskList, localActivity.task.params.WorkflowInfo.TaskListName)
16241621
var laResult string
16251622
err = result.Get(&laResult)
16261623
s.NoError(err)

internal/workflow_testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (t *TestActivityEnvironment) ExecuteActivity(activityFn interface{}, args .
159159

160160
// ExecuteLocalActivity executes a local activity. The tested activity will be executed synchronously in the calling goroutinue.
161161
// Caller should use Value.Get() to extract strong typed result value.
162-
func (t *TestActivityEnvironment) ExecuteLocalActivity(activityFn interface{}, args ...interface{}) (val Value, result *localActivityResult, err error) {
162+
func (t *TestActivityEnvironment) ExecuteLocalActivity(activityFn interface{}, args ...interface{}) (val Value, err error) {
163163
return t.impl.executeLocalActivity(activityFn, args...)
164164
}
165165

test/activity_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package test
2222

2323
import (
2424
"context"
25+
"fmt"
2526
"strings"
2627
"sync"
2728
"time"
@@ -88,6 +89,21 @@ func (a *Activities) Fail(ctx context.Context) error {
8889
return errFailOnPurpose
8990
}
9091

92+
func (a *Activities) InspectActivityInfo(ctx context.Context, domain, taskList, wfType string) error {
93+
a.append("inspectActivityInfo")
94+
info := activity.GetInfo(ctx)
95+
if info.WorkflowDomain != domain {
96+
return fmt.Errorf("expected domainName %v but got %v", domain, info.WorkflowDomain)
97+
}
98+
if info.WorkflowType == nil || info.WorkflowType.Name != wfType {
99+
return fmt.Errorf("expected workflowType %v but got %v", wfType, info.WorkflowType)
100+
}
101+
if info.TaskList != taskList {
102+
return fmt.Errorf("expected taskList %v but got %v", taskList, info.TaskList)
103+
}
104+
return nil
105+
}
106+
91107
func (a *Activities) append(name string) {
92108
a.Lock()
93109
defer a.Unlock()
@@ -118,4 +134,5 @@ func (a *Activities) register() {
118134
activity.RegisterWithOptions(a.HeartbeatAndSleep, activity.RegisterOptions{Name: "heartbeatAndSleep"})
119135
activity.RegisterWithOptions(a.GetMemoAndSearchAttr, activity.RegisterOptions{Name: "getMemoAndSearchAttr"})
120136
activity.RegisterWithOptions(a.RetryTimeoutStableErrorActivity, activity.RegisterOptions{Name: "retryTimeoutStableErrorActivity"})
137+
activity.RegisterWithOptions(a.InspectActivityInfo, activity.RegisterOptions{Name: "inspectActivityInfo"})
121138
}

test/integration_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ func (ts *IntegrationTestSuite) TestLargeQueryResultError() {
401401
ts.Nil(value)
402402
}
403403

404+
func (ts *IntegrationTestSuite) TestInspectActivityInfo() {
405+
err := ts.executeWorkflow("test-activity-info", ts.workflows.InspectActivityInfo, nil)
406+
ts.Nil(err)
407+
}
408+
409+
func (ts *IntegrationTestSuite) TestInspectLocalActivityInfo() {
410+
err := ts.executeWorkflow("test-local-activity-info", ts.workflows.InspectLocalActivityInfo, nil)
411+
ts.Nil(err)
412+
}
413+
404414
func (ts *IntegrationTestSuite) registerDomain() {
405415
client := client.NewDomainClient(ts.rpcClient.Interface, &client.Options{})
406416
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)

test/workflow_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,26 @@ func (w *Workflows) sleep(ctx workflow.Context, d time.Duration) error {
494494
return workflow.ExecuteActivity(ctx, "sleep", d).Get(ctx, nil)
495495
}
496496

497+
func (w *Workflows) InspectActivityInfo(ctx workflow.Context) error {
498+
info := workflow.GetInfo(ctx)
499+
domain := info.Domain
500+
wfType := info.WorkflowType.Name
501+
taskList := info.TaskListName
502+
ctx = workflow.WithActivityOptions(ctx, w.defaultActivityOptions())
503+
return workflow.ExecuteActivity(ctx, "inspectActivityInfo", domain, taskList, wfType).Get(ctx, nil)
504+
}
505+
506+
func (w *Workflows) InspectLocalActivityInfo(ctx workflow.Context) error {
507+
info := workflow.GetInfo(ctx)
508+
domain := info.Domain
509+
wfType := info.WorkflowType.Name
510+
taskList := info.TaskListName
511+
ctx = workflow.WithLocalActivityOptions(ctx, w.defaultLocalActivityOptions())
512+
activites := Activities{}
513+
return workflow.ExecuteLocalActivity(
514+
ctx, activites.InspectActivityInfo, domain, taskList, wfType).Get(ctx, nil)
515+
}
516+
497517
func (w *Workflows) register() {
498518
workflow.Register(w.Basic)
499519
workflow.Register(w.ActivityRetryOnError)
@@ -508,6 +528,8 @@ func (w *Workflows) register() {
508528
workflow.Register(w.ChildWorkflowSuccess)
509529
workflow.Register(w.ChildWorkflowSuccessWithParentClosePolicyTerminate)
510530
workflow.Register(w.ChildWorkflowSuccessWithParentClosePolicyAbandon)
531+
workflow.Register(w.InspectActivityInfo)
532+
workflow.Register(w.InspectLocalActivityInfo)
511533
workflow.Register(w.sleep)
512534
workflow.Register(w.child)
513535
workflow.Register(w.childForMemoAndSearchAttr)
@@ -525,6 +547,13 @@ func (w *Workflows) defaultActivityOptions() workflow.ActivityOptions {
525547
StartToCloseTimeout: 9 * time.Second,
526548
}
527549
}
550+
551+
func (w *Workflows) defaultLocalActivityOptions() workflow.LocalActivityOptions {
552+
return workflow.LocalActivityOptions{
553+
ScheduleToCloseTimeout: 5 * time.Second,
554+
}
555+
}
556+
528557
func (w *Workflows) defaultActivityOptionsWithRetry() workflow.ActivityOptions {
529558
return workflow.ActivityOptions{
530559
ScheduleToStartTimeout: 5 * time.Second,

0 commit comments

Comments
 (0)