Files
tasks/service/history/queues/mitigator_test.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

132 lines
2.7 KiB
Go

package queues
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.temporal.io/server/common/clock"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/log"
"go.temporal.io/server/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,
_ log.Logger,
) {
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,
_ log.Logger,
) {
}
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
}