mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 06:07:27 +08:00
feat(ai-proxy): add cooldownDuration support for failover token recovery (#3700)
Signed-off-by: wydream <yaodiwu618@gmail.com> Signed-off-by: woody <yaodiwu618@gmail.com>
This commit is contained in:
@@ -538,6 +538,50 @@ func TestFailover_FromJson_Defaults(t *testing.T) {
|
||||
assert.Equal(t, int64(8000), f.healthCheckTimeout)
|
||||
assert.Equal(t, "test-model", f.healthCheckModel)
|
||||
})
|
||||
|
||||
t.Run("cooldown_duration_default", func(t *testing.T) {
|
||||
f := &failover{}
|
||||
jsonStr := `{"enabled": true}`
|
||||
f.FromJson(gjson.Parse(jsonStr))
|
||||
assert.Equal(t, int64(0), f.cooldownDuration)
|
||||
})
|
||||
|
||||
t.Run("cooldown_duration_custom", func(t *testing.T) {
|
||||
f := &failover{}
|
||||
jsonStr := `{"enabled": true, "cooldownDuration": 60000}`
|
||||
f.FromJson(gjson.Parse(jsonStr))
|
||||
assert.Equal(t, int64(60000), f.cooldownDuration)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFailover_Validate(t *testing.T) {
|
||||
t.Run("only_healthCheckModel", func(t *testing.T) {
|
||||
f := &failover{healthCheckModel: "gpt-3.5-turbo"}
|
||||
assert.NoError(t, f.Validate())
|
||||
})
|
||||
|
||||
t.Run("only_cooldownDuration", func(t *testing.T) {
|
||||
f := &failover{cooldownDuration: 60000}
|
||||
assert.NoError(t, f.Validate())
|
||||
})
|
||||
|
||||
t.Run("both_healthCheckModel_and_cooldownDuration", func(t *testing.T) {
|
||||
f := &failover{healthCheckModel: "gpt-3.5-turbo", cooldownDuration: 60000}
|
||||
assert.NoError(t, f.Validate())
|
||||
})
|
||||
|
||||
t.Run("neither_healthCheckModel_nor_cooldownDuration", func(t *testing.T) {
|
||||
f := &failover{}
|
||||
err := f.Validate()
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "either healthCheckModel or cooldownDuration")
|
||||
})
|
||||
|
||||
t.Run("negative_cooldownDuration", func(t *testing.T) {
|
||||
f := &failover{cooldownDuration: -1}
|
||||
err := f.Validate()
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFailover_FromJson_FailoverOnStatus(t *testing.T) {
|
||||
@@ -565,19 +609,6 @@ func TestFailover_FromJson_FailoverOnStatus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestFailover_Validate(t *testing.T) {
|
||||
t.Run("missing_healthCheckModel", func(t *testing.T) {
|
||||
f := &failover{}
|
||||
f.FromJson(gjson.Parse(`{"enabled":true}`))
|
||||
assert.Error(t, f.Validate())
|
||||
})
|
||||
t.Run("ok_with_healthCheckModel", func(t *testing.T) {
|
||||
f := &failover{}
|
||||
f.FromJson(gjson.Parse(`{"enabled":true,"healthCheckModel":"gpt-4o-mini"}`))
|
||||
assert.NoError(t, f.Validate())
|
||||
})
|
||||
}
|
||||
|
||||
func TestHealthCheckEndpoint_Struct(t *testing.T) {
|
||||
t.Run("health_check_endpoint_fields", func(t *testing.T) {
|
||||
endpoint := HealthCheckEndpoint{
|
||||
|
||||
Reference in New Issue
Block a user