Files
tasks/service/matching/configs/quotas_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

97 lines
2.1 KiB
Go

package configs
import (
"reflect"
"slices"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/hanzoai/tasks/api/matchingservice/v1"
"github.com/hanzoai/tasks/common/headers"
"github.com/hanzoai/tasks/common/quotas"
"github.com/hanzoai/tasks/common/testing/temporalapi"
)
type (
quotasSuite struct {
suite.Suite
*require.Assertions
}
)
func TestQuotasSuite(t *testing.T) {
s := new(quotasSuite)
suite.Run(t, s)
}
func (s *quotasSuite) SetupSuite() {
}
func (s *quotasSuite) TearDownSuite() {
}
func (s *quotasSuite) SetupTest() {
s.Assertions = require.New(s.T())
}
func (s *quotasSuite) TearDownTest() {
}
func (s *quotasSuite) TestAPIToPriorityMapping() {
for _, priority := range APIToPriority {
index := slices.Index(APIPrioritiesOrdered, priority)
s.NotEqual(-1, index)
}
}
func (s *quotasSuite) TestAPIPrioritiesOrdered() {
for idx := range APIPrioritiesOrdered[1:] {
s.True(APIPrioritiesOrdered[idx] < APIPrioritiesOrdered[idx+1])
}
}
func (s *quotasSuite) TestAPIs() {
var service matchingservice.MatchingServiceServer
apiToPriority := make(map[string]int)
temporalapi.WalkExportedMethods(&service, func(m reflect.Method) {
fullName := "/temporal.server.api.matchingservice.v1.MatchingService/" + m.Name
apiToPriority[fullName] = APIToPriority[fullName]
})
s.Equal(apiToPriority, APIToPriority)
}
func (s *quotasSuite) TestOperatorPrioritized() {
rateFn := func() float64 { return 5 }
operatorRPSRatioFn := func() float64 { return 0.2 }
limiter := NewPriorityRateLimiter(rateFn, operatorRPSRatioFn)
operatorRequest := quotas.NewRequest(
"/temporal.server.api.matchingservice.v1.MatchingService/QueryWorkflow",
1,
"",
headers.CallerTypeOperator,
-1,
"")
apiRequest := quotas.NewRequest(
"/temporal.server.api.matchingservice.v1.MatchingService/QueryWorkflow",
1,
"",
headers.CallerTypeAPI,
-1,
"")
requestTime := time.Now()
limitCount := 0
for range 12 {
if !limiter.Allow(requestTime, apiRequest) {
limitCount++
s.True(limiter.Allow(requestTime, operatorRequest))
}
}
s.Equal(2, limitCount)
}