Skip to content

Commit

Permalink
refactor/testing domain update callback (cadence-workflow#6365)
Browse files Browse the repository at this point in the history
This predominantly adds some unit test coverage for the domain callback function triggered during domain updates and failovers. It also does some refactoring to enable such test coverage and fixes a few associated minor issues.
  • Loading branch information
davidporter-id-au authored Oct 16, 2024
1 parent d4b375d commit f2452ed
Show file tree
Hide file tree
Showing 22 changed files with 789 additions and 519 deletions.
18 changes: 12 additions & 6 deletions common/cache/domainCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,21 @@ func NewDomainCacheEntryForTest(
repConfig *persistence.DomainReplicationConfig,
failoverVersion int64,
failoverEndtime *int64,
failoverNotificationVersion int64,
previousFailoverVersion int64,
notificationVersion int64,
) *DomainCacheEntry {

return &DomainCacheEntry{
info: info,
config: config,
isGlobalDomain: isGlobalDomain,
replicationConfig: repConfig,
failoverVersion: failoverVersion,
failoverEndTime: failoverEndtime,
info: info,
config: config,
isGlobalDomain: isGlobalDomain,
replicationConfig: repConfig,
failoverVersion: failoverVersion,
failoverEndTime: failoverEndtime,
failoverNotificationVersion: failoverNotificationVersion,
previousFailoverVersion: previousFailoverVersion,
notificationVersion: notificationVersion,
}
}

Expand Down
3 changes: 3 additions & 0 deletions common/cache/domainCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ func Test_IsActiveIn(t *testing.T) {
&persistence.DomainReplicationConfig{ActiveClusterName: tt.activeCluster},
0,
tt.failoverDeadline,
0,
0,
0,
)

isActive, err := domain.IsActiveIn(tt.currentCluster)
Expand Down
3 changes: 2 additions & 1 deletion common/domain/failover_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (s *failoverWatcherSuite) TestHandleFailoverTimeout() {
replicationConfig,
1,
endtime,
0, 0, 0,
)
s.watcher.handleFailoverTimeout(domainEntry)
}
Expand Down Expand Up @@ -284,7 +285,7 @@ func (s *failoverWatcherSuite) TestRefreshDomainLoop() {
domainInfo := &persistence.DomainInfo{ID: domainID, Name: domainName}
domainConfig := &persistence.DomainConfig{Retention: 1, EmitMetric: true}
replicationConfig := &persistence.DomainReplicationConfig{ActiveClusterName: "active", Clusters: []*persistence.ClusterReplicationConfig{{ClusterName: "active"}}}
domainEntry := cache.NewDomainCacheEntryForTest(domainInfo, domainConfig, true, replicationConfig, 1, failoverEndTime)
domainEntry := cache.NewDomainCacheEntryForTest(domainInfo, domainConfig, true, replicationConfig, 1, failoverEndTime, 0, 0, 0)

domainsMap := map[string]*cache.DomainCacheEntry{domainID: domainEntry}
s.mockDomainCache.EXPECT().GetAllDomain().Return(domainsMap).AnyTimes()
Expand Down
24 changes: 12 additions & 12 deletions common/isolationgroup/defaultisolationgroupstate/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
},
dcAffordance: func(client *dynamicconfig.MockClient) {},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomainName("domain-id").Return("domain", nil)
},
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(dynamicConfigResponseNormal, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomainName("domain-id").Return("domain", nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(dynamicConfigResponseDrained, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomainName("domain-id").Return("domain", nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
Expand All @@ -173,7 +173,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(nil, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomainName("domain-id").Return("domain", nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(nil, fmt.Errorf("an error"))
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
},
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(nil, fmt.Errorf("an error"))
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
},
Expand All @@ -252,7 +252,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
dcAffordance: func(client *dynamicconfig.MockClient) {
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(nil, errors.New("a failure")).AnyTimes()
},
Expand All @@ -268,7 +268,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
dcAffordance: func(client *dynamicconfig.MockClient) {
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(nil, nil).AnyTimes()
},
Expand All @@ -288,7 +288,7 @@ func TestAvailableIsolationGroupsHandler(t *testing.T) {
).Return(nil, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomainName("domain-id").Return("domain", nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil).AnyTimes()
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestIsDrainedHandler(t *testing.T) {
).Return(dynamicConfigResponse, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil)
},
Expand All @@ -381,7 +381,7 @@ func TestIsDrainedHandler(t *testing.T) {
).Return(dynamicConfigResponse, nil)
},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
mock.EXPECT().GetDomain("domain").Return(domainResponse, nil)
},
Expand All @@ -395,7 +395,7 @@ func TestIsDrainedHandler(t *testing.T) {
},
dcAffordance: func(client *dynamicconfig.MockClient) {},
domainAffordance: func(mock *cache.MockDomainCache) {
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil)
domainResponse := cache.NewDomainCacheEntryForTest(&persistence.DomainInfo{ID: "domain-id", Name: "domain"}, &persistence.DomainConfig{}, true, nil, 0, nil, 0, 0, 0)
mock.EXPECT().GetDomainByID("domain-id").Return(domainResponse, nil)
},
expected: false,
Expand Down
126 changes: 0 additions & 126 deletions config/development_cross_region_cluster0.yaml

This file was deleted.

Loading

0 comments on commit f2452ed

Please sign in to comment.