@@ -304,6 +304,7 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
304304
305305 tests := []struct {
306306 name string
307+ runID string
307308 activeClusterCfg * types.ActiveClusters
308309 domainIDToNameErr error
309310 mockExecutionManagerFn func (em * persistence.MockExecutionManager )
@@ -313,7 +314,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
313314 expectedError string
314315 }{
315316 {
316- name : "domain ID to name function returns error" ,
317+ name : "domain ID to name function returns error" ,
318+ runID : "test-run-id" ,
317319 activeClusterCfg : & types.ActiveClusters {
318320 AttributeScopes : map [string ]types.ClusterAttributeScope {
319321 "region" : {
@@ -330,7 +332,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
330332 expectedError : "failed to find domain by id" ,
331333 },
332334 {
333- name : "execution manager provider returns error" ,
335+ name : "execution manager provider returns error" ,
336+ runID : "test-run-id" ,
334337 activeClusterCfg : & types.ActiveClusters {
335338 AttributeScopes : map [string ]types.ClusterAttributeScope {
336339 "region" : {
@@ -349,7 +352,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
349352 expectedError : "failed to get execution manager" ,
350353 },
351354 {
352- name : "execution manager GetActiveClusterSelectionPolicy returns error" ,
355+ name : "execution manager GetActiveClusterSelectionPolicy returns error" ,
356+ runID : "test-run-id" ,
353357 activeClusterCfg : & types.ActiveClusters {
354358 AttributeScopes : map [string ]types.ClusterAttributeScope {
355359 "region" : {
@@ -369,7 +373,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
369373 expectedError : "database error" ,
370374 },
371375 {
372- name : "policy not found (EntityNotExistsError) - uses empty policy with nil cluster attribute" ,
376+ name : "policy not found (EntityNotExistsError) - uses empty policy with nil cluster attribute" ,
377+ runID : "test-run-id" ,
373378 activeClusterCfg : & types.ActiveClusters {
374379 AttributeScopes : map [string ]types.ClusterAttributeScope {
375380 "region" : {
@@ -392,7 +397,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
392397 },
393398 },
394399 {
395- name : "policy not found (EntityNotExistsError) - empty policy with cluster attribute not found" ,
400+ name : "policy not found (EntityNotExistsError) - empty policy with cluster attribute not found" ,
401+ runID : "test-run-id" ,
396402 activeClusterCfg : & types.ActiveClusters {
397403 AttributeScopes : map [string ]types.ClusterAttributeScope {
398404 "region" : {
@@ -415,7 +421,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
415421 },
416422 },
417423 {
418- name : "policy found but cluster attribute not found in domain config" ,
424+ name : "policy found but cluster attribute not found in domain config" ,
425+ runID : "test-run-id" ,
419426 activeClusterCfg : & types.ActiveClusters {
420427 AttributeScopes : map [string ]types.ClusterAttributeScope {
421428 "region" : {
@@ -440,7 +447,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
440447 expectedError : "could not find cluster attribute &{datacenter dc1} in the domain test-domain-id's active cluster config" ,
441448 },
442449 {
443- name : "successful lookup - policy found and cluster attribute exists" ,
450+ name : "successful lookup - policy found and cluster attribute exists" ,
451+ runID : "test-run-id" ,
444452 activeClusterCfg : & types.ActiveClusters {
445453 AttributeScopes : map [string ]types.ClusterAttributeScope {
446454 "region" : {
@@ -472,7 +480,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
472480 },
473481 },
474482 {
475- name : "successful lookup - policy from cache" ,
483+ name : "successful lookup - policy from cache" ,
484+ runID : "test-run-id" ,
476485 activeClusterCfg : & types.ActiveClusters {
477486 AttributeScopes : map [string ]types.ClusterAttributeScope {
478487 "datacenter" : {
@@ -495,14 +504,17 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
495504 Name : "dc2" ,
496505 },
497506 },
498- // No mock needed since policy comes from cache
507+ mockExecutionManagerFn : func (em * persistence.MockExecutionManager ) {
508+ // No expectations needed since policy comes from cache, but we need the provider to be non-nil
509+ },
499510 expectedResult : & types.ActiveClusterInfo {
500511 ActiveClusterName : "cluster1" ,
501512 FailoverVersion : 250 ,
502513 },
503514 },
504515 {
505- name : "successful lookup - nil cluster attribute in policy uses domain-level info" ,
516+ name : "successful lookup - nil cluster attribute in policy uses domain-level info" ,
517+ runID : "test-run-id" ,
506518 activeClusterCfg : & types.ActiveClusters {
507519 AttributeScopes : map [string ]types.ClusterAttributeScope {
508520 "region" : {
@@ -527,7 +539,8 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
527539 },
528540 },
529541 {
530- name : "successful lookup - multiple scopes with different attributes" ,
542+ name : "successful lookup - multiple scopes with different attributes" ,
543+ runID : "test-run-id" ,
531544 activeClusterCfg : & types.ActiveClusters {
532545 AttributeScopes : map [string ]types.ClusterAttributeScope {
533546 "region" : {
@@ -566,6 +579,71 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
566579 FailoverVersion : 300 ,
567580 },
568581 },
582+ {
583+ name : "successful lookup - empty runID triggers GetCurrentExecution" ,
584+ runID : "" ,
585+ activeClusterCfg : & types.ActiveClusters {
586+ AttributeScopes : map [string ]types.ClusterAttributeScope {
587+ "region" : {
588+ ClusterAttributes : map [string ]types.ActiveClusterInfo {
589+ "us-west" : {
590+ ActiveClusterName : "cluster0" ,
591+ FailoverVersion : 100 ,
592+ },
593+ "us-east" : {
594+ ActiveClusterName : "cluster1" ,
595+ FailoverVersion : 200 ,
596+ },
597+ },
598+ },
599+ },
600+ },
601+ mockExecutionManagerFn : func (em * persistence.MockExecutionManager ) {
602+ // Expect GetCurrentExecution to be called first to get the runID
603+ em .EXPECT ().GetCurrentExecution (gomock .Any (), & persistence.GetCurrentExecutionRequest {
604+ DomainID : "test-domain-id" ,
605+ WorkflowID : "test-workflow-id" ,
606+ }).Return (& persistence.GetCurrentExecutionResponse {
607+ RunID : "current-run-id" ,
608+ }, nil )
609+ // Then expect GetActiveClusterSelectionPolicy with the returned runID
610+ em .EXPECT ().GetActiveClusterSelectionPolicy (gomock .Any (), "test-domain-id" , "test-workflow-id" , "current-run-id" ).
611+ Return (& types.ActiveClusterSelectionPolicy {
612+ ClusterAttribute : & types.ClusterAttribute {
613+ Scope : "region" ,
614+ Name : "us-east" ,
615+ },
616+ }, nil )
617+ },
618+ expectedResult : & types.ActiveClusterInfo {
619+ ActiveClusterName : "cluster1" ,
620+ FailoverVersion : 200 ,
621+ },
622+ },
623+ {
624+ name : "empty runID - GetCurrentExecution returns error" ,
625+ runID : "" ,
626+ activeClusterCfg : & types.ActiveClusters {
627+ AttributeScopes : map [string ]types.ClusterAttributeScope {
628+ "region" : {
629+ ClusterAttributes : map [string ]types.ActiveClusterInfo {
630+ "us-west" : {
631+ ActiveClusterName : "cluster0" ,
632+ FailoverVersion : 100 ,
633+ },
634+ },
635+ },
636+ },
637+ },
638+ mockExecutionManagerFn : func (em * persistence.MockExecutionManager ) {
639+ // GetCurrentExecution returns an error
640+ em .EXPECT ().GetCurrentExecution (gomock .Any (), & persistence.GetCurrentExecutionRequest {
641+ DomainID : "test-domain-id" ,
642+ WorkflowID : "test-workflow-id" ,
643+ }).Return (nil , errors .New ("workflow not found" ))
644+ },
645+ expectedError : "workflow not found" ,
646+ },
569647 }
570648
571649 for _ , tc := range tests {
@@ -605,11 +683,11 @@ func TestGetActiveClusterInfoByWorkflow(t *testing.T) {
605683 assert .NoError (t , err )
606684
607685 if tc .cachedPolicy != nil {
608- key := fmt .Sprintf ("%s:%s:%s" , "test-domain-id" , wfID , "test-run-id" )
686+ key := fmt .Sprintf ("%s:%s:%s" , "test-domain-id" , wfID , tc . runID )
609687 mgr .(* managerImpl ).workflowPolicyCache .Put (key , tc .cachedPolicy )
610688 }
611689
612- result , err := mgr .GetActiveClusterInfoByWorkflow (context .Background (), "test-domain-id" , wfID , "test-run-id" )
690+ result , err := mgr .GetActiveClusterInfoByWorkflow (context .Background (), "test-domain-id" , wfID , tc . runID )
613691 if tc .expectedError != "" {
614692 assert .EqualError (t , err , tc .expectedError )
615693 assert .Nil (t , result )
0 commit comments