Files
tasks/service/frontend/validators_test.go
Stephan BehnkeandGitHub a0067a2aef Fairness weight override API (#8379)
## What changed?

Adds the ability to set/unset fairness weight overrides by fairness key
via `UpdateTaskQueueConfig` API.

From the API:

> // Fairness weight for a task can come from multiple sources for
    // flexibility. From highest to lowest precedence:
// 1. Weights for a small set of keys can be overridden in task queue
    //    configuration with an API.
    // 2. It can be attached to the workflow/activity in this field.
    // 3. The default weight of 1.0 will be used.
    //
    // Weight values are clamped to the range [0.001, 1000].

## Why?

To allow users to fine-tune their fairness key behavior via the API. 

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [x] added new functional test(s)

## Potential risks
N/A
2025-10-17 00:37:31 +00:00

78 lines
2.1 KiB
Go

package frontend
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestValidateFairnessWeightUpdate(t *testing.T) {
t.Run("set overrides", func(t *testing.T) {
set := map[string]float32{
"a": 1.0,
"b": 2.3,
}
unset := []string{}
err := validateFairnessWeightUpdate(set, unset, 10)
require.NoError(t, err)
})
t.Run("unset overrides", func(t *testing.T) {
set := map[string]float32{}
unset := []string{"z"}
err := validateFairnessWeightUpdate(set, unset, 10)
require.NoError(t, err)
})
t.Run("enforce max number of overrides", func(t *testing.T) {
set := map[string]float32{
"a": 1.0,
}
unset := []string{"z"}
err := validateFairnessWeightUpdate(set, unset, 10)
require.NoError(t, err)
err = validateFairnessWeightUpdate(set, unset, 2)
require.NoError(t, err)
err = validateFairnessWeightUpdate(set, unset, 1)
require.ErrorContains(t, err, "too many fairness weight overrides in request: got 2, maximum 1")
})
t.Run("reject too long key in `set`", func(t *testing.T) {
set := map[string]float32{
strings.Repeat("abcdefg", 10): 1.0,
}
unset := []string{}
err := validateFairnessWeightUpdate(set, unset, 10)
require.ErrorContains(t, err, "fairness key length exceeds limit")
})
t.Run("reject too long key in `unset`", func(t *testing.T) {
set := map[string]float32{"a": 1.0}
unset := []string{strings.Repeat("abcdefg", 10)}
err := validateFairnessWeightUpdate(set, unset, 10)
require.ErrorContains(t, err, "fairness key length exceeds limit")
})
t.Run("reject negative weight", func(t *testing.T) {
set := map[string]float32{
"a": -2.0,
}
unset := []string{}
err := validateFairnessWeightUpdate(set, unset, 10)
require.ErrorContains(t, err, "invalid fairness weight weight for key \"a\": must be greater than zero")
})
t.Run("reject overlap between `set` and `unset`", func(t *testing.T) {
set := map[string]float32{
"a": 1.0,
}
unset := []string{"a"}
err := validateFairnessWeightUpdate(set, unset, 10)
require.ErrorContains(t, err, "fairness weight override key \"a\" present in both set and unset lists")
})
}