mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
84 lines
1.6 KiB
Go
84 lines
1.6 KiB
Go
package configs
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/hanzoai/tasks/common/headers"
|
|
"github.com/hanzoai/tasks/common/quotas"
|
|
)
|
|
|
|
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) TestCallerTypeToPriorityMapping() {
|
|
for _, priority := range CallerTypeToPriority {
|
|
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) TestOperatorPrioritized() {
|
|
rateFn := func() float64 { return 5 }
|
|
operatorRPSRatioFn := func() float64 { return 0.2 }
|
|
limiter := NewPriorityRateLimiter(rateFn, operatorRPSRatioFn)
|
|
|
|
operatorRequest := quotas.NewRequest(
|
|
"/temporal.server.api.historyservice.v1.HistoryService/StartWorkflowExecution",
|
|
1,
|
|
"",
|
|
headers.CallerTypeOperator,
|
|
-1,
|
|
"")
|
|
|
|
apiRequest := quotas.NewRequest(
|
|
"/temporal.server.api.historyservice.v1.HistoryService/StartWorkflowExecution",
|
|
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)
|
|
}
|