Skip to content

Commit 641292b

Browse files
authored
Revert breaking changes in v1.2.8 (#1315)
* Revert "Making Workflow and Activity registration optional when they are mocked (#1256)" This reverts commit 2e73362. * Revert "Addressing difference in workflow interceptors when using the testkit (#1257)" This reverts commit e31ba38.
1 parent bc2753a commit 641292b

File tree

3 files changed

+2
-123
lines changed

3 files changed

+2
-123
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ func (env *testWorkflowEnvironmentImpl) newTestWorkflowEnvironmentForChild(param
362362
childEnv.startedHandler = startedHandler
363363
childEnv.testWorkflowEnvironmentShared = env.testWorkflowEnvironmentShared
364364
childEnv.workerOptions = env.workerOptions
365-
childEnv.workflowInterceptors = env.workflowInterceptors
366365
childEnv.workerOptions.DataConverter = params.dataConverter
367366
childEnv.workflowInterceptors = env.workflowInterceptors
368367
childEnv.registry = env.registry

internal/workflow_testsuite.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ func (t *TestWorkflowEnvironment) OnActivity(activity interface{}, args ...inter
240240
panic(err)
241241
}
242242
fnName := getActivityFunctionName(t.impl.registry, activity)
243-
t.impl.registry.RegisterActivityWithOptions(activity, RegisterActivityOptions{DisableAlreadyRegisteredCheck: true})
244243
call = t.Mock.On(fnName, args...)
244+
245245
case reflect.String:
246246
call = t.Mock.On(activity.(string), args...)
247247
default:
@@ -289,12 +289,11 @@ func (t *TestWorkflowEnvironment) OnWorkflow(workflow interface{}, args ...inter
289289
if alias, ok := t.impl.registry.getWorkflowAlias(fnName); ok {
290290
fnName = alias
291291
}
292-
t.impl.registry.RegisterWorkflowWithOptions(workflow, RegisterWorkflowOptions{DisableAlreadyRegisteredCheck: true})
293292
call = t.Mock.On(fnName, args...)
294293
case reflect.String:
295294
call = t.Mock.On(workflow.(string), args...)
296295
default:
297-
panic("workflow must be function or string")
296+
panic("activity must be function or string")
298297
}
299298

300299
return t.wrapCall(call)

internal/workflow_testsuite_test.go

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ package internal
2323

2424
import (
2525
"context"
26-
"github.com/stretchr/testify/mock"
27-
"github.com/stretchr/testify/suite"
2826
"strings"
2927
"testing"
3028
"time"
@@ -129,120 +127,3 @@ func TestWorkflowReturnNil(t *testing.T) {
129127
err := env.GetWorkflowResult(&r)
130128
require.NoError(t, err)
131129
}
132-
133-
func HelloWorkflow(ctx Context, name string) (string, error) {
134-
ctx = WithActivityOptions(ctx, ActivityOptions{
135-
ScheduleToCloseTimeout: time.Hour,
136-
StartToCloseTimeout: time.Hour,
137-
ScheduleToStartTimeout: time.Hour,
138-
})
139-
var result string
140-
err := ExecuteActivity(ctx, HelloActivity, name).Get(ctx, &result)
141-
return result, err
142-
}
143-
144-
func HelloActivity(ctx context.Context, name string) (string, error) {
145-
return "Hello " + name + "!", nil
146-
}
147-
148-
func TestWorkflowMockingWithoutRegistration(t *testing.T) {
149-
testSuite := &WorkflowTestSuite{}
150-
env := testSuite.NewTestWorkflowEnvironment()
151-
env.OnWorkflow(HelloWorkflow, mock.Anything, mock.Anything).Return(
152-
func(ctx Context, person string) (string, error) {
153-
return "Hello " + person + "!", nil
154-
})
155-
// Workflow is mocked, no activity registration required
156-
env.ExecuteWorkflow(HelloWorkflow, "Cadence")
157-
require.NoError(t, env.GetWorkflowError())
158-
var result string
159-
err := env.GetWorkflowResult(&result)
160-
require.NoError(t, err)
161-
require.Equal(t, "Hello Cadence!", result)
162-
}
163-
164-
func TestActivityMockingWithoutRegistration(t *testing.T) {
165-
testSuite := &WorkflowTestSuite{}
166-
env := testSuite.NewTestWorkflowEnvironment()
167-
env.OnActivity(HelloActivity, mock.Anything, mock.Anything).Return(
168-
func(ctx context.Context, person string) (string, error) {
169-
return "Goodbye " + person + "!", nil
170-
})
171-
// Registration of activity not required
172-
env.RegisterWorkflow(HelloWorkflow)
173-
env.ExecuteWorkflow(HelloWorkflow, "Cadence")
174-
require.NoError(t, env.GetWorkflowError())
175-
var result string
176-
err := env.GetWorkflowResult(&result)
177-
require.NoError(t, err)
178-
require.Equal(t, "Goodbye Cadence!", result)
179-
180-
type InterceptorTestSuite struct {
181-
suite.Suite
182-
WorkflowTestSuite
183-
184-
env *TestWorkflowEnvironment
185-
testFactory InterceptorFactory
186-
}
187-
188-
type InterceptorFactory struct {
189-
workflowInterceptorInvocationCounter int
190-
childWorkflowInterceptorInvocationCounter int
191-
}
192-
193-
type Interceptor struct {
194-
WorkflowInterceptorBase
195-
workflowInterceptorInvocationCounter *int
196-
childWorkflowInterceptorInvocationCounter *int
197-
}
198-
199-
func (i *Interceptor) ExecuteWorkflow(ctx Context, workflowType string, args ...interface{}) []interface{} {
200-
*i.workflowInterceptorInvocationCounter += 1
201-
return i.Next.ExecuteWorkflow(ctx, workflowType, args...)
202-
}
203-
func (i *Interceptor) ExecuteChildWorkflow(ctx Context, workflowType string, args ...interface{}) ChildWorkflowFuture {
204-
*i.childWorkflowInterceptorInvocationCounter += 1
205-
return i.Next.ExecuteChildWorkflow(ctx, workflowType, args...)
206-
}
207-
208-
func (f *InterceptorFactory) NewInterceptor(_ *WorkflowInfo, next WorkflowInterceptor) WorkflowInterceptor {
209-
return &Interceptor{
210-
WorkflowInterceptorBase: WorkflowInterceptorBase{
211-
Next: next,
212-
},
213-
workflowInterceptorInvocationCounter: &f.workflowInterceptorInvocationCounter,
214-
childWorkflowInterceptorInvocationCounter: &f.childWorkflowInterceptorInvocationCounter,
215-
}
216-
}
217-
218-
func (s *InterceptorTestSuite) SetupTest() {
219-
// Create a test workflow environment with the trace interceptor configured.
220-
s.env = s.NewTestWorkflowEnvironment()
221-
s.testFactory = InterceptorFactory{}
222-
s.env.SetWorkerOptions(WorkerOptions{
223-
WorkflowInterceptorChainFactories: []WorkflowInterceptorFactory{
224-
&s.testFactory,
225-
},
226-
})
227-
}
228-
229-
func TestInterceptorTestSuite(t *testing.T) {
230-
suite.Run(t, new(InterceptorTestSuite))
231-
}
232-
233-
func (s *InterceptorTestSuite) Test_GeneralInterceptor_IsExecutedOnChildren() {
234-
r := s.Require()
235-
childWf := func(ctx Context) error {
236-
return nil
237-
}
238-
s.env.RegisterWorkflowWithOptions(childWf, RegisterWorkflowOptions{Name: "child"})
239-
wf := func(ctx Context) error {
240-
return ExecuteChildWorkflow(ctx, childWf).Get(ctx, nil)
241-
}
242-
s.env.RegisterWorkflowWithOptions(wf, RegisterWorkflowOptions{Name: "parent"})
243-
s.env.ExecuteWorkflow(wf)
244-
r.True(s.env.IsWorkflowCompleted())
245-
r.NoError(s.env.GetWorkflowError())
246-
r.Equal(s.testFactory.workflowInterceptorInvocationCounter, 2)
247-
r.Equal(s.testFactory.childWorkflowInterceptorInvocationCounter, 1)
248-
}

0 commit comments

Comments
 (0)