Files
tasks/service/history/queues/mitigator_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

130 lines
2.7 KiB
Go

package queues
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/hanzoai/tasks/common/clock"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/metrics"
)
type (
mitigatorSuite struct {
suite.Suite
*require.Assertions
mockTimeSource *clock.EventTimeSource
monitor *testMonitor
mitigator *mitigatorImpl
}
testMonitor struct {
Monitor
resolvedAlertType AlertType
}
)
func TestMitigatorSuite(t *testing.T) {
s := new(mitigatorSuite)
suite.Run(t, s)
}
func (s *mitigatorSuite) SetupTest() {
s.Assertions = require.New(s.T())
s.mockTimeSource = clock.NewEventTimeSource()
s.monitor = &testMonitor{}
// we use a different actionRunner implementation,
// which doesn't require readerGroup
s.mitigator = newMitigator(
nil,
s.monitor,
log.NewTestLogger(),
metrics.NoopMetricsHandler,
dynamicconfig.GetIntPropertyFn(3),
GrouperNamespaceID{},
)
}
func (s *mitigatorSuite) TestMitigate_ActionMatchAlert() {
testCases := []struct {
alert Alert
expectedAction Action
}{
{
alert: Alert{
AlertType: AlertTypeQueuePendingTaskCount,
AlertAttributesQueuePendingTaskCount: &AlertAttributesQueuePendingTaskCount{
CurrentPendingTaskCount: 1000,
CiriticalPendingTaskCount: 500,
},
},
expectedAction: &actionQueuePendingTask{},
},
{
alert: Alert{
AlertType: AlertTypeReaderStuck,
AlertAttributesReaderStuck: &AlertAttributesReaderStuck{
ReaderID: 1,
CurrentWatermark: NewRandomKey(),
},
},
expectedAction: &actionReaderStuck{},
},
{
alert: Alert{
AlertType: AlertTypeSliceCount,
AlertAttributesSliceCount: &AlertAttributesSlicesCount{
CurrentSliceCount: 1000,
CriticalSliceCount: 500,
},
},
expectedAction: &actionSliceCount{},
},
}
var actualAction Action
s.mitigator.actionRunner = func(
action Action,
_ *ReaderGroup,
_ metrics.Handler,
) {
actualAction = action
}
for _, tc := range testCases {
s.mitigator.Mitigate(tc.alert)
s.IsType(tc.expectedAction, actualAction)
}
}
func (s *mitigatorSuite) TestMitigate_ResolveAlert() {
s.mitigator.actionRunner = func(
_ Action,
_ *ReaderGroup,
_ metrics.Handler,
) {
}
alert := Alert{
AlertType: AlertTypeQueuePendingTaskCount,
AlertAttributesQueuePendingTaskCount: &AlertAttributesQueuePendingTaskCount{
CurrentPendingTaskCount: 1000,
CiriticalPendingTaskCount: 500,
},
}
s.mitigator.Mitigate(alert)
s.Equal(alert.AlertType, s.monitor.resolvedAlertType)
}
func (m *testMonitor) ResolveAlert(alertType AlertType) {
m.resolvedAlertType = alertType
}