Skip to content

Commit

Permalink
Add unit test to cover functions in task allocator (cadence-workflow#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timl3136 authored Oct 28, 2024
1 parent 75339a3 commit d29b674
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions service/history/queue/task_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package queue

import (
"errors"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -72,6 +73,8 @@ func (s *TaskAllocatorSuite) SetupTest() {

s.taskDomainID = "testDomainID"
s.task = "testTask"
s.allocator.Lock()
s.allocator.Unlock()
}

func (s *TaskAllocatorSuite) TearDownTest() {
Expand Down Expand Up @@ -366,3 +369,54 @@ func (s *TaskAllocatorSuite) TestVerifyStandbyTask() {
})
}
}

func (s *TaskAllocatorSuite) TestIsDomainNotRegistered() {
tests := []struct {
name string
domainID string
mockFn func()
expectedErrorString string
}{
{
name: "domainID return error",
mockFn: func() {
s.mockDomainCache.EXPECT().GetDomainByID("").Return(nil, fmt.Errorf("testError"))
},
domainID: "",
expectedErrorString: "testError",
},
{
name: "cannot get info",
domainID: "testDomainID",
mockFn: func() {
domainEntry := cache.NewDomainCacheEntryForTest(nil, nil, false, nil, 0, nil, 0, 0, 0)
s.mockDomainCache.EXPECT().GetDomainByID("testDomainID").Return(domainEntry, nil)
},
expectedErrorString: "domain info is nil in cache",
},
{
name: "domain is deprecated",
domainID: "testDomainID",
mockFn: func() {
domainEntry := cache.NewDomainCacheEntryForTest(
&persistence.DomainInfo{Status: persistence.DomainStatusDeprecated}, nil, false, nil, 0, nil, 0, 0, 0)
s.mockDomainCache.EXPECT().GetDomainByID("testDomainID").Return(domainEntry, nil)
},
expectedErrorString: "",
},
}

for _, tt := range tests {
s.Run(tt.name, func() {
tt.mockFn()
res, err := isDomainNotRegistered(s.mockShard, tt.domainID)
if tt.expectedErrorString != "" {
assert.ErrorContains(s.T(), err, tt.expectedErrorString)
assert.False(s.T(), res)
} else {
assert.NoError(s.T(), err)
assert.True(s.T(), res)
}
})
}
}

0 comments on commit d29b674

Please sign in to comment.