mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-21 06:56:58 +00:00
Merge pull request #5392 from fengshao1227/fix/grok-405-failover-and-cooldown
fix(grok): 405 纳入 failover 与临时踢号,修复 Grok 会话粘性锁死
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShouldFailoverUpstreamError_405IsFailoverEligible(t *testing.T) {
|
||||
svc := &OpenAIGatewayService{}
|
||||
|
||||
assert.True(t, svc.shouldFailoverUpstreamError(http.StatusMethodNotAllowed),
|
||||
"405 should trigger failover so sticky sessions can escape to healthy accounts")
|
||||
}
|
||||
|
||||
func TestShouldFailoverUpstreamError_ExistingCodesStillWork(t *testing.T) {
|
||||
svc := &OpenAIGatewayService{}
|
||||
|
||||
failoverCodes := []int{401, 402, 403, 405, 429, 529, 500, 502, 503, 504}
|
||||
for _, code := range failoverCodes {
|
||||
assert.True(t, svc.shouldFailoverUpstreamError(code), "status %d should trigger failover", code)
|
||||
}
|
||||
|
||||
nonFailoverCodes := []int{200, 201, 400, 404, 408, 422}
|
||||
for _, code := range nonFailoverCodes {
|
||||
assert.False(t, svc.shouldFailoverUpstreamError(code), "status %d should NOT trigger failover", code)
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func isOpenAIContextWindowError(upstreamMsg string, upstreamBody []byte) bool {
|
||||
|
||||
func (s *OpenAIGatewayService) shouldFailoverUpstreamError(statusCode int) bool {
|
||||
switch statusCode {
|
||||
case 401, 402, 403, 429, 529:
|
||||
case 401, 402, 403, 405, 429, 529:
|
||||
return true
|
||||
default:
|
||||
return statusCode >= 500
|
||||
|
||||
Reference in New Issue
Block a user