Release v1.4.7 with unlimited default timeout
This commit is contained in:
@@ -75,9 +75,6 @@ func New(cfg Config) *Client {
|
||||
if cfg.CosyVersion == "" {
|
||||
cfg.CosyVersion = "2.11.2"
|
||||
}
|
||||
if cfg.Timeout <= 0 {
|
||||
cfg.Timeout = 300 * time.Second
|
||||
}
|
||||
cfg.BaseURL = strings.TrimRight(cfg.BaseURL, "/")
|
||||
return &Client{cfg: cfg, client: &http.Client{Timeout: cfg.Timeout}}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,23 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNewKeepsZeroTimeoutUnlimited(t *testing.T) {
|
||||
client := New(Config{Timeout: 0})
|
||||
if client.client.Timeout != 0 {
|
||||
t.Fatalf("timeout = %v, want 0", client.client.Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKeepsPositiveTimeout(t *testing.T) {
|
||||
client := New(Config{Timeout: 7 * time.Second})
|
||||
if client.client.Timeout != 7*time.Second {
|
||||
t.Fatalf("timeout = %v, want 7s", client.client.Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractBaseURLFromEndpointLog(t *testing.T) {
|
||||
got := extractBaseURLFromText(`2026-04-10 INFO Update endpoint success. endpoint config: https://ai-lingma-cmb01-cn-beijing.rdc.aliyuncs.com`)
|
||||
want := "https://ai-lingma-cmb01-cn-beijing.rdc.aliyuncs.com"
|
||||
|
||||
@@ -167,9 +167,6 @@ func New(cfg Config) *Service {
|
||||
if strings.TrimSpace(cfg.ShellType) == "" {
|
||||
cfg.ShellType = lingmaipc.DefaultShellType()
|
||||
}
|
||||
if cfg.Timeout <= 0 {
|
||||
cfg.Timeout = 300 * time.Second
|
||||
}
|
||||
if cfg.Transport == "" {
|
||||
cfg.Transport = lingmaipc.TransportAuto
|
||||
}
|
||||
@@ -225,6 +222,13 @@ func (s *Service) Close() error {
|
||||
return s.closeClientLocked()
|
||||
}
|
||||
|
||||
func contextWithOptionalTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
if timeout <= 0 {
|
||||
return context.WithCancel(parent)
|
||||
}
|
||||
return context.WithTimeout(parent, timeout)
|
||||
}
|
||||
|
||||
func (s *Service) State() State {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@@ -365,7 +369,7 @@ func (s *Service) generateRemote(
|
||||
client := s.remoteClientLocked()
|
||||
var lastErr error
|
||||
for i, model := range models {
|
||||
attemptCtx, cancel := context.WithTimeout(ctx, s.cfg.Timeout)
|
||||
attemptCtx, cancel := contextWithOptionalTimeout(ctx, s.cfg.Timeout)
|
||||
result, emitted, err := s.generateRemoteWithModel(attemptCtx, client, req, prompt, model, onDelta)
|
||||
cancel()
|
||||
if err == nil {
|
||||
@@ -513,7 +517,7 @@ func (s *Service) generateLocked(
|
||||
req ChatRequest,
|
||||
onDelta func(string),
|
||||
) (result *ChatResult, err error) {
|
||||
requestCtx, cancel := context.WithTimeout(ctx, s.cfg.Timeout)
|
||||
requestCtx, cancel := contextWithOptionalTimeout(ctx, s.cfg.Timeout)
|
||||
defer cancel()
|
||||
|
||||
ipcClient, err := s.ensureConnected(requestCtx)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsRecoverableIPCError(t *testing.T) {
|
||||
@@ -23,3 +25,26 @@ func TestIsRecoverableIPCErrorIgnoresModelErrors(t *testing.T) {
|
||||
t.Fatal("timeout should not be treated as an immediate reconnect retry")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKeepsZeroTimeoutUnlimited(t *testing.T) {
|
||||
svc := New(Config{Timeout: 0})
|
||||
if svc.cfg.Timeout != 0 {
|
||||
t.Fatalf("timeout = %v, want 0", svc.cfg.Timeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextWithOptionalTimeoutZeroDoesNotSetDeadline(t *testing.T) {
|
||||
ctx, cancel := contextWithOptionalTimeout(context.Background(), 0)
|
||||
defer cancel()
|
||||
if _, ok := ctx.Deadline(); ok {
|
||||
t.Fatal("zero timeout should not set a deadline")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextWithOptionalTimeoutPositiveSetsDeadline(t *testing.T) {
|
||||
ctx, cancel := contextWithOptionalTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if _, ok := ctx.Deadline(); !ok {
|
||||
t.Fatal("positive timeout should set a deadline")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user