Skip to content

Commit 6cd0267

Browse files
authored
Export GetRegisteredWorkflowTypes so I can use it for shadow testing. (#1202)
1 parent 53618e8 commit 6cd0267

File tree

7 files changed

+19
-7
lines changed

7 files changed

+19
-7
lines changed

internal/internal_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func (aw *aggregatedWorker) Start() error {
789789
}
790790

791791
if aw.workflowWorker != nil {
792-
if len(aw.registry.getRegisteredWorkflowTypes()) == 0 {
792+
if len(aw.registry.GetRegisteredWorkflowTypes()) == 0 {
793793
aw.logger.Info(
794794
"Worker has no workflows registered, so workflow worker will not be started.",
795795
)

internal/internal_worker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (s *internalWorkerTestSuite) TestNoActivitiesOrWorkflows() {
250250
w := createWorker(s.T(), s.service)
251251
w.registry = newRegistry()
252252
assert.Empty(t, w.registry.getRegisteredActivities())
253-
assert.Empty(t, w.registry.getRegisteredWorkflowTypes())
253+
assert.Empty(t, w.registry.GetRegisteredWorkflowTypes())
254254
assert.NoError(t, w.Start())
255255
}
256256

internal/internal_workflow_testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func (env *testWorkflowEnvironmentImpl) executeWorkflowInternal(delayStart time.
517517
func (env *testWorkflowEnvironmentImpl) getWorkflowDefinition(wt WorkflowType) (workflowDefinition, error) {
518518
wf, ok := env.registry.getWorkflowFn(wt.Name)
519519
if !ok {
520-
supported := strings.Join(env.registry.getRegisteredWorkflowTypes(), ", ")
520+
supported := strings.Join(env.registry.GetRegisteredWorkflowTypes(), ", ")
521521
return nil, fmt.Errorf("unable to find workflow type: %v. Supported types: [%v]", wt.Name, supported)
522522
}
523523
wd := &workflowExecutorWrapper{

internal/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,15 @@ func (r *registry) getWorkflowNoLock(registerName string) (interface{}, bool) {
243243
return a, ok
244244
}
245245

246-
func (r *registry) getRegisteredWorkflowTypes() []string {
246+
func (r *registry) GetRegisteredWorkflowTypes() []string {
247247
r.Lock() // do not defer for Unlock to call next.getRegisteredWorkflowTypes without lock
248248
var result []string
249249
for t := range r.workflowFuncMap {
250250
result = append(result, t)
251251
}
252252
r.Unlock()
253253
if r.next != nil {
254-
nextTypes := r.next.getRegisteredWorkflowTypes()
254+
nextTypes := r.next.GetRegisteredWorkflowTypes()
255255
result = append(result, nextTypes...)
256256
}
257257
return result
@@ -318,7 +318,7 @@ func (r *registry) getWorkflowDefinition(wt WorkflowType) (workflowDefinition, e
318318
}
319319
wf, ok := r.getWorkflowFn(lookup)
320320
if !ok {
321-
supported := strings.Join(r.getRegisteredWorkflowTypes(), ", ")
321+
supported := strings.Join(r.GetRegisteredWorkflowTypes(), ", ")
322322
return nil, fmt.Errorf(errMsgUnknownWorkflowType+": %v. Supported types: [%v]", lookup, supported)
323323
}
324324
wd := &workflowExecutor{workflowType: lookup, fn: wf}

internal/registry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestWorkflowRegistration(t *testing.T) {
105105
tt.register(r)
106106

107107
// Verify registered workflow type
108-
workflowType := r.getRegisteredWorkflowTypes()[0]
108+
workflowType := r.GetRegisteredWorkflowTypes()[0]
109109
require.Equal(t, tt.workflowType, workflowType)
110110

111111
// Verify workflow is resolved from workflow type

internal/workflow.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,13 @@ func RegisterWorkflowWithOptions(workflowFunc interface{}, opts RegisterWorkflow
581581
registry.RegisterWorkflowWithOptions(workflowFunc, opts)
582582
}
583583

584+
// GetRegisteredWorkflowTypes returns the registered workflow function/alias names.
585+
// The public form is: workflow.GetRegisteredWorkflowTypes(...)
586+
func GetRegisteredWorkflowTypes() []string {
587+
registry := getGlobalRegistry()
588+
return registry.GetRegisteredWorkflowTypes()
589+
}
590+
584591
// Await blocks the calling thread until condition() returns true
585592
// Returns CanceledError if the ctx is canceled.
586593
func Await(ctx Context, condition func() bool) error {

workflow/workflow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func RegisterWithOptions(workflowFunc interface{}, opts RegisterOptions) {
8989
internal.RegisterWorkflowWithOptions(workflowFunc, opts)
9090
}
9191

92+
// GetRegisteredWorkflowTypes returns the registered workflow function/alias names.
93+
func GetRegisteredWorkflowTypes() []string {
94+
return internal.GetRegisteredWorkflowTypes()
95+
}
96+
9297
// ExecuteActivity requests activity execution in the context of a workflow.
9398
// Context can be used to pass the settings for this activity.
9499
// For example: task list that this need to be routed, timeouts that need to be configured.

0 commit comments

Comments
 (0)