Refactor llm client timeout
This commit is contained in:
@@ -3,6 +3,7 @@ package llm
|
||||
import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestConfigValidate(t *testing.T) {
|
||||
@@ -22,10 +23,10 @@ func TestConfigValidate(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid timeout",
|
||||
name: "negative timeout",
|
||||
cfg: Config{
|
||||
URL: "http://localhost:8080",
|
||||
Timeout: "not-a-duration",
|
||||
Timeout: -time.Second,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
@@ -40,7 +41,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
name: "valid config with timeout",
|
||||
cfg: Config{
|
||||
URL: "http://localhost:8080",
|
||||
Timeout: "15m",
|
||||
Timeout: 15 * time.Minute,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
@@ -48,7 +49,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
name: "valid config with complex timeout",
|
||||
cfg: Config{
|
||||
URL: "http://localhost:8080",
|
||||
Timeout: "1h30m45s",
|
||||
Timeout: time.Hour + 30*time.Minute + 45*time.Second,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
@@ -56,7 +57,7 @@ func TestConfigValidate(t *testing.T) {
|
||||
name: "valid full config",
|
||||
cfg: Config{
|
||||
Key: "sk-test-key",
|
||||
Timeout: "30m",
|
||||
Timeout: 30 * time.Minute,
|
||||
URL: "http://localhost:8080",
|
||||
},
|
||||
wantErr: false,
|
||||
@@ -89,6 +90,14 @@ func TestNewClient(t *testing.T) {
|
||||
cfg: Config{},
|
||||
wantErr: "invalid config: missing URL",
|
||||
},
|
||||
{
|
||||
name: "negative timeout precedes nil logger",
|
||||
cfg: Config{
|
||||
URL: "http://localhost:8080",
|
||||
Timeout: -time.Second,
|
||||
},
|
||||
wantErr: "invalid config: invalid timeout -1s: must not be negative",
|
||||
},
|
||||
{
|
||||
name: "nil logger",
|
||||
cfg: Config{
|
||||
@@ -107,7 +116,7 @@ func TestNewClient(t *testing.T) {
|
||||
name: "valid config with timeout",
|
||||
cfg: Config{
|
||||
URL: "http://localhost:8080",
|
||||
Timeout: "10m",
|
||||
Timeout: 10 * time.Minute,
|
||||
},
|
||||
log: log,
|
||||
},
|
||||
@@ -115,7 +124,7 @@ func TestNewClient(t *testing.T) {
|
||||
name: "valid config with all fields",
|
||||
cfg: Config{
|
||||
Key: "test-key",
|
||||
Timeout: "5m",
|
||||
Timeout: 5 * time.Minute,
|
||||
URL: "http://localhost:8080",
|
||||
},
|
||||
log: log,
|
||||
@@ -144,7 +153,14 @@ func TestNewClient(t *testing.T) {
|
||||
t.Fatalf("NewClient() error = %v, want nil", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Error("NewClient() client = nil, want non-nil")
|
||||
t.Fatal("NewClient() client = nil, want non-nil")
|
||||
}
|
||||
wantTimeout := tt.cfg.Timeout
|
||||
if wantTimeout == 0 {
|
||||
wantTimeout = 5 * time.Minute
|
||||
}
|
||||
if client.timeout != wantTimeout {
|
||||
t.Errorf("timeout = %v, want %v", client.timeout, wantTimeout)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user