responses 直通超时可配,流式去总超时,代理补阶段超时
CI / test (push) Successful in 31s

This commit is contained in:
2026-07-16 21:20:02 +08:00
parent d56678e1de
commit cb66567256
13 changed files with 379 additions and 45 deletions
+37 -2
View File
@@ -83,7 +83,7 @@ func (f *gatewayStubClient) GenAiApplyGuardrails(ctx context.Context, cred oci.C
return f.guardOutcome, f.guardErr
}
func (f *gatewayStubClient) GenAiCompatResponses(ctx context.Context, cred oci.Credentials, region string, body []byte) ([]byte, error) {
func (f *gatewayStubClient) GenAiCompatResponses(ctx context.Context, cred oci.Credentials, region string, body []byte, wait time.Duration) ([]byte, error) {
f.passCalls++
f.passRegions = append(f.passRegions, region)
if len(f.passErrs) > 0 {
@@ -96,7 +96,7 @@ func (f *gatewayStubClient) GenAiCompatResponses(ctx context.Context, cred oci.C
return f.passPayload, nil
}
func (f *gatewayStubClient) GenAiCompatResponsesStream(ctx context.Context, cred oci.Credentials, region string, body []byte) (io.ReadCloser, error) {
func (f *gatewayStubClient) GenAiCompatResponsesStream(ctx context.Context, cred oci.Credentials, region string, body []byte, wait time.Duration) (io.ReadCloser, error) {
f.passCalls++
f.passRegions = append(f.passRegions, region)
if len(f.passErrs) > 0 {
@@ -1124,3 +1124,38 @@ func TestAggregatedModelsFilterDeprecated(t *testing.T) {
t.Fatalf("开关开:弃用模型应被过滤, got %+v", items)
}
}
func TestUpstreamWaitSetting(t *testing.T) {
gw, _ := newTestGateway(t, &gatewayStubClient{fakeClient: &fakeClient{}})
ctx := context.Background()
if got := gw.UpstreamWait(); got != 300*time.Second {
t.Fatalf("缺省上游无响应预算 = %v, 期望 300s", got)
}
tests := []struct {
name string
sec int
wantErr bool
}{
{name: "下界 30 有效", sec: 30},
{name: "上界 900 有效", sec: 900},
{name: "低于下界拒绝", sec: 29, wantErr: true},
{name: "高于上界拒绝", sec: 901, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := gw.SetUpstreamWait(ctx, tt.sec)
if (err != nil) != tt.wantErr {
t.Fatalf("SetUpstreamWait(%d) = %v, wantErr=%v", tt.sec, err, tt.wantErr)
}
if !tt.wantErr && gw.UpstreamWait() != time.Duration(tt.sec)*time.Second {
t.Fatalf("UpstreamWait = %v, 期望 %ds", gw.UpstreamWait(), tt.sec)
}
})
}
// 持久化后新实例应加载已存值(最后一次成功设置为 900)
gw2 := NewAiGatewayService(gw.db, nil, nil)
if got := gw2.UpstreamWait(); got != 900*time.Second {
t.Fatalf("重建服务加载预算 = %v, 期望 900s", got)
}
}