fix(runner): 延长媒体上游请求超时
图像生成上游同步响应可能超过 120 秒,原共享 HTTP 客户端会把仍在处理的提交标记为结果不确定。将客户端超时调整为 10 分钟,并增加回归测试;任务执行仍由现有租约、任务超时和取消机制约束。\n\n验证:\n- env -u AI_GATEWAY_TEST_DATABASE_URL go test ./internal/runner -run 'TestProviderHTTPClientTimeoutAllowsLongRunningMediaRequests|TestPlatformProxyMode' -count=1\n- env -u AI_GATEWAY_TEST_DATABASE_URL go test ./... -count=1
This commit is contained in:
@@ -19,6 +19,8 @@ type httpClientCache struct {
|
|||||||
custom map[string]*http.Client
|
custom map[string]*http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const providerHTTPClientTimeout = 10 * time.Minute
|
||||||
|
|
||||||
func newHTTPClientCache() *httpClientCache {
|
func newHTTPClientCache() *httpClientCache {
|
||||||
return &httpClientCache{
|
return &httpClientCache{
|
||||||
none: newHTTPClient(nil),
|
none: newHTTPClient(nil),
|
||||||
@@ -67,7 +69,7 @@ func newHTTPClient(proxy func(*http.Request) (*url.URL, error)) *http.Client {
|
|||||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
transport.Proxy = proxy
|
transport.Proxy = proxy
|
||||||
return &http.Client{
|
return &http.Client{
|
||||||
Timeout: 120 * time.Second,
|
Timeout: providerHTTPClientTimeout,
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,19 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/config"
|
"github.com/easyai/easyai-ai-gateway/apps/api/internal/config"
|
||||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestProviderHTTPClientTimeoutAllowsLongRunningMediaRequests(t *testing.T) {
|
||||||
|
client := newHTTPClient(nil)
|
||||||
|
if client.Timeout != 10*time.Minute {
|
||||||
|
t.Fatalf("unexpected provider HTTP timeout: got %s want %s", client.Timeout, 10*time.Minute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPlatformProxyModeNoneIgnoresEnvironmentProxy(t *testing.T) {
|
func TestPlatformProxyModeNoneIgnoresEnvironmentProxy(t *testing.T) {
|
||||||
var proxyHits int
|
var proxyHits int
|
||||||
proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user