refactor(executor): remove immediate retry with token refresh on 429 for Qwen and update tests accordingly

This commit is contained in:
Luis Pater
2026-04-11 16:35:18 +08:00
parent 5ab9afac83
commit 828df80088
2 changed files with 27 additions and 82 deletions
+27 -29
View File
@@ -216,7 +216,7 @@ func TestQwenCreds_NormalizesResourceURL(t *testing.T) {
}
}
func TestQwenExecutorExecute_429RefreshAndRetry(t *testing.T) {
func TestQwenExecutorExecute_429DoesNotRefreshOrRetry(t *testing.T) {
qwenRateLimiter.Lock()
qwenRateLimiter.requests = make(map[string][]time.Time)
qwenRateLimiter.Unlock()
@@ -272,27 +272,31 @@ func TestQwenExecutorExecute_429RefreshAndRetry(t *testing.T) {
}
ctx := context.Background()
resp, err := exec.Execute(ctx, auth, cliproxyexecutor.Request{
_, err := exec.Execute(ctx, auth, cliproxyexecutor.Request{
Model: "qwen-max",
Payload: []byte(`{"model":"qwen-max","messages":[{"role":"user","content":"hi"}]}`),
}, cliproxyexecutor.Options{
SourceFormat: sdktranslator.FromString("openai"),
})
if err != nil {
t.Fatalf("Execute() error = %v", err)
if err == nil {
t.Fatalf("Execute() expected error, got nil")
}
if len(resp.Payload) == 0 {
t.Fatalf("Execute() payload is empty")
status, ok := err.(statusErr)
if !ok {
t.Fatalf("Execute() error type = %T, want statusErr", err)
}
if atomic.LoadInt32(&calls) != 2 {
t.Fatalf("upstream calls = %d, want 2", atomic.LoadInt32(&calls))
if status.StatusCode() != http.StatusTooManyRequests {
t.Fatalf("Execute() status code = %d, want %d", status.StatusCode(), http.StatusTooManyRequests)
}
if atomic.LoadInt32(&refresherCalls) != 1 {
t.Fatalf("refresher calls = %d, want 1", atomic.LoadInt32(&refresherCalls))
if atomic.LoadInt32(&calls) != 1 {
t.Fatalf("upstream calls = %d, want 1", atomic.LoadInt32(&calls))
}
if atomic.LoadInt32(&refresherCalls) != 0 {
t.Fatalf("refresher calls = %d, want 0", atomic.LoadInt32(&refresherCalls))
}
}
func TestQwenExecutorExecuteStream_429RefreshAndRetry(t *testing.T) {
func TestQwenExecutorExecuteStream_429DoesNotRefreshOrRetry(t *testing.T) {
qwenRateLimiter.Lock()
qwenRateLimiter.requests = make(map[string][]time.Time)
qwenRateLimiter.Unlock()
@@ -351,32 +355,26 @@ func TestQwenExecutorExecuteStream_429RefreshAndRetry(t *testing.T) {
}
ctx := context.Background()
stream, err := exec.ExecuteStream(ctx, auth, cliproxyexecutor.Request{
_, err := exec.ExecuteStream(ctx, auth, cliproxyexecutor.Request{
Model: "qwen-max",
Payload: []byte(`{"model":"qwen-max","stream":true,"messages":[{"role":"user","content":"hi"}]}`),
}, cliproxyexecutor.Options{
SourceFormat: sdktranslator.FromString("openai"),
})
if err != nil {
t.Fatalf("ExecuteStream() error = %v", err)
if err == nil {
t.Fatalf("ExecuteStream() expected error, got nil")
}
if atomic.LoadInt32(&calls) != 2 {
t.Fatalf("upstream calls = %d, want 2", atomic.LoadInt32(&calls))
status, ok := err.(statusErr)
if !ok {
t.Fatalf("ExecuteStream() error type = %T, want statusErr", err)
}
if atomic.LoadInt32(&refresherCalls) != 1 {
t.Fatalf("refresher calls = %d, want 1", atomic.LoadInt32(&refresherCalls))
if status.StatusCode() != http.StatusTooManyRequests {
t.Fatalf("ExecuteStream() status code = %d, want %d", status.StatusCode(), http.StatusTooManyRequests)
}
var sawPayload bool
for chunk := range stream.Chunks {
if chunk.Err != nil {
t.Fatalf("stream chunk error = %v", chunk.Err)
}
if len(chunk.Payload) > 0 {
sawPayload = true
}
if atomic.LoadInt32(&calls) != 1 {
t.Fatalf("upstream calls = %d, want 1", atomic.LoadInt32(&calls))
}
if !sawPayload {
t.Fatalf("stream did not produce any payload chunks")
if atomic.LoadInt32(&refresherCalls) != 0 {
t.Fatalf("refresher calls = %d, want 0", atomic.LoadInt32(&refresherCalls))
}
}