func (t *TestWorkflowEnvironment) SetTestTimeout(idleTimeout time.Duration) *TestWorkflowEnvironment {
	t.impl.testTimeout = idleTimeout
	return t
}
SetTestTimeout sets the idle timeout based on wall clock for this tested workflow. Idle is when workflow is blocked
waiting on events (including timer, activity, child workflow, signal etc). If there is no event happening longer than
this idle timeout, the test framework would stop the workflow and return timeout error.
This is based on real wall clock time, not the workflow time (a.k.a workflow.Now() time).
package internal
import (
	"context"
	"fmt"
	"reflect"
	"time"
	"github.com/stretchr/testify/mock"
	"github.com/uber-go/tally"
	"go.uber.org/cadence/.gen/go/shared"
	"go.uber.org/zap"
)
type (
	EncodedValues struct {
		values        []byte
		dataConverter DataConverter
	}
	WorkflowTestSuite struct {
		logger   *zap.Logger
		scope    tally.Scope
		ctxProps []ContextPropagator
		header   *shared.Header
	}
	TestWorkflowEnvironment struct {
		mock.Mock
		impl *testWorkflowEnvironmentImpl
	}
	TestActivityEnvironment struct {
		impl *testWorkflowEnvironmentImpl
	}
	MockCallWrapper struct {
		call *mock.Call
		env  *TestWorkflowEnvironment
		runFn        func(args mock.Arguments)
		waitDuration func() time.Duration
	}
)
func newEncodedValues(values []byte, dc DataConverter) Values {
	if dc == nil {
		dc = getDefaultDataConverter()
	}
	return &EncodedValues{values, dc}
}
func (b EncodedValues) Get(valuePtr ...interface{}) error {
	if !b.HasValues() {
		return ErrNoData
	}
	return b.dataConverter.FromData(b.values, valuePtr...)
}
func (b EncodedValues) HasValues() bool {
	return b.values != nil
}
func (s *WorkflowTestSuite) NewTestWorkflowEnvironment() *TestWorkflowEnvironment {
	return &TestWorkflowEnvironment{impl: newTestWorkflowEnvironmentImpl(s, nil)}
}
func (s *WorkflowTestSuite) NewTestActivityEnvironment() *TestActivityEnvironment {
	return &TestActivityEnvironment{impl: newTestWorkflowEnvironmentImpl(s, nil)}
}
func (s *WorkflowTestSuite) SetLogger(logger *zap.Logger) {
	s.logger = logger
}
func (s *WorkflowTestSuite) GetLogger() *zap.Logger {
	return s.logger
}
func (s *WorkflowTestSuite) SetMetricsScope(scope tally.Scope) {
	s.scope = scope
}
func (s *WorkflowTestSuite) SetContextPropagators(ctxProps []ContextPropagator) {
	s.ctxProps = ctxProps
}
func (s *WorkflowTestSuite) SetHeader(header *shared.Header) {
	s.header = header
}
func (t *TestActivityEnvironment) RegisterActivity(a interface{}) {
	t.impl.RegisterActivity(a)
}
func (t *TestActivityEnvironment) RegisterActivityWithOptions(a interface{}, options RegisterActivityOptions) {
	t.impl.RegisterActivityWithOptions(a, options)
}
func (t *TestActivityEnvironment) ExecuteActivity(activityFn interface{}, args ...interface{}) (Value, error) {
	return t.impl.executeActivity(activityFn, args...)
}
func (t *TestActivityEnvironment) ExecuteLocalActivity(activityFn interface{}, args ...interface{}) (val Value, err error) {
	return t.impl.executeLocalActivity(activityFn, args...)
}
func (t *TestActivityEnvironment) SetWorkerOptions(options WorkerOptions) *TestActivityEnvironment {
	t.impl.setWorkerOptions(options)
	return t
}
func (t *TestActivityEnvironment) SetTestTimeout(idleTimeout time.Duration) *TestActivityEnvironment {
	t.impl.testTimeout = idleTimeout
	return t
}
func (t *TestActivityEnvironment) SetHeartbeatDetails(details interface{}) {
	t.impl.setHeartbeatDetails(details)
}
func (t *TestActivityEnvironment) SetWorkerStopChannel(c chan struct{}) {
	t.impl.setWorkerStopChannel(c)
}
func (t *TestWorkflowEnvironment) RegisterWorkflow(w interface{}) {
	t.impl.RegisterWorkflow(w)
}
func (t *TestWorkflowEnvironment) RegisterWorkflowWithOptions(w interface{}, options RegisterWorkflowOptions) {
	if len(t.ExpectedCalls) > 0 {
		panic("RegisterWorkflow calls cannot follow mock related ones like OnWorkflow or similar")
	}
	t.impl.RegisterWorkflowWithOptions(w, options)
}
func (t *TestWorkflowEnvironment) RegisterActivity(a interface{}) {
	t.impl.RegisterActivity(a)
}
func (t *TestWorkflowEnvironment) RegisterActivityWithOptions(a interface{}, options RegisterActivityOptions) {
	if len(t.ExpectedCalls) > 0 {
		panic("RegisterActivity calls cannot follow mock related ones like OnActivity or similar")
	}
	t.impl.RegisterActivityWithOptions(a, options)
}
func (t *TestWorkflowEnvironment) SetStartTime(startTime time.Time) {
	t.impl.setStartTime(startTime)
}
func (t *TestWorkflowEnvironment) OnActivity(activity interface{}, args ...interface{}) *MockCallWrapper {
	fType := reflect.TypeOf(activity)
	var call *mock.Call
	switch fType.Kind() {
	case reflect.Func:
		fnType := reflect.TypeOf(activity)
		if err := validateFnFormat(fnType, false); err != nil {
			panic(err)
		}
		fnName := getActivityFunctionName(t.impl.registry, activity)
		call = t.Mock.On(fnName, args...)
	case reflect.String:
		call = t.Mock.On(activity.(string), args...)
	default:
		panic("activity must be function or string")
	}
	return t.wrapCall(call)
}
var ErrMockStartChildWorkflowFailed = fmt.Errorf("start child workflow failed: %v", shared.ChildWorkflowExecutionFailedCauseWorkflowAlreadyRunning)
func (t *TestWorkflowEnvironment) OnWorkflow(workflow interface{}, args ...interface{}) *MockCallWrapper {
	fType := reflect.TypeOf(workflow)
	var call *mock.Call
	switch fType.Kind() {
	case reflect.Func:
		fnType := reflect.TypeOf(workflow)
		if err := validateFnFormat(fnType, true); err != nil {
			panic(err)
		}
		fnName := getWorkflowFunctionName(t.impl.registry, workflow)
		if alias, ok := t.impl.registry.getWorkflowAlias(fnName); ok {
			fnName = alias
		}
		call = t.Mock.On(fnName, args...)
	case reflect.String:
		call = t.Mock.On(workflow.(string), args...)
	default:
		panic("activity must be function or string")
	}
	return t.wrapCall(call)
}
const mockMethodForSignalExternalWorkflow = "workflow.SignalExternalWorkflow"
const mockMethodForRequestCancelExternalWorkflow = "workflow.RequestCancelExternalWorkflow"
const mockMethodForGetVersion = "workflow.GetVersion"
const mockMethodForUpsertSearchAttributes = "workflow.UpsertSearchAttributes"
func (t *TestWorkflowEnvironment) OnSignalExternalWorkflow(domainName, workflowID, runID, signalName, arg interface{}) *MockCallWrapper {
	call := t.Mock.On(mockMethodForSignalExternalWorkflow, domainName, workflowID, runID, signalName, arg)
	return t.wrapCall(call)
}
func (t *TestWorkflowEnvironment) OnRequestCancelExternalWorkflow(domainName, workflowID, runID string) *MockCallWrapper {
	call := t.Mock.On(mockMethodForRequestCancelExternalWorkflow, domainName, workflowID, runID)
	return t.wrapCall(call)
}
func (t *TestWorkflowEnvironment) OnGetVersion(changeID string, minSupported, maxSupported Version) *MockCallWrapper {
	call := t.Mock.On(getMockMethodForGetVersion(changeID), changeID, minSupported, maxSupported)
	return t.wrapCall(call)
}
func (t *TestWorkflowEnvironment) OnUpsertSearchAttributes(attributes map[string]interface{}) *MockCallWrapper {
	call := t.Mock.On(mockMethodForUpsertSearchAttributes, attributes)
	return t.wrapCall(call)
}
func (t *TestWorkflowEnvironment) wrapCall(call *mock.Call) *MockCallWrapper {
	callWrapper := &MockCallWrapper{call: call, env: t}
	call.Run(t.impl.getMockRunFn(callWrapper))
	return callWrapper
}
func (c *MockCallWrapper) Once() *MockCallWrapper {
	return c.Times(1)
}
func (c *MockCallWrapper) Twice() *MockCallWrapper {
	return c.Times(2)
}
func (c *MockCallWrapper) Times(i int) *MockCallWrapper {
	c.call.Times(i)
	return c
}
func (c *MockCallWrapper) Run(fn func(args mock.Arguments)) *MockCallWrapper {
	c.runFn = fn
	return c
}
func (c *MockCallWrapper) After(d time.Duration) *MockCallWrapper {
	c.waitDuration = func() time.Duration { return d }
	return c
}
func (c *MockCallWrapper) AfterFn(fn func() time.Duration) *MockCallWrapper {
	c.waitDuration = fn
	return c
}
func (c *MockCallWrapper) Return(returnArguments ...interface{}) *MockCallWrapper {
	c.call.Return(returnArguments...)
	return c
}
func (t *TestWorkflowEnvironment) ExecuteWorkflow(workflowFn interface{}, args ...interface{}) {
	t.impl.mock = &t.Mock
	t.impl.executeWorkflow(workflowFn, args...)
}
func (t *TestWorkflowEnvironment) Now() time.Time {
	return t.impl.Now()
}
func (t *TestWorkflowEnvironment) SetWorkerOptions(options WorkerOptions) *TestWorkflowEnvironment {
	t.impl.setWorkerOptions(options)
	return t
}
func (t *TestWorkflowEnvironment) SetWorkerStopChannel(c chan struct{}) {
	t.impl.setWorkerStopChannel(c)
}