Files
traefik-llmgateway/resp_notapplied_test.go
T
lukaszraczyloandGitHub 979d903c19 feat: admin redesign, decision assist, prompt caching and shared state (#11)
This change adds the redesigned admin panel and the smart router decision model assist.
It adds opt-in prompt-prefix caching per provider and cached-token pricing and metrics.
With Redis, the metrics route reports fleet-wide values. The redis.sharedState switch shares six coordination states across replicas.
PR CI grants actions read, which the shared go-pr workflow needs.
The pull request description has the full list and the verification.
2026-11-26 15:50:11 +00:00

99 lines
2.7 KiB
Go

package traefikllmgateway
import (
"bufio"
"fmt"
"testing"
"time"
)
func TestRESPPipelineNotApplied(t *testing.T) {
incr := [][]string{{"INCRBY", "k", "1"}, {"EXPIRE", "k", "60"}}
t.Run("dial failure was never written", func(t *testing.T) {
ln := newFakeListener(t)
addr := ln.Addr().String()
_ = ln.Close()
c := newRESPClient(addr, "", 0)
_, err := c.pipeline(incr)
if err == nil {
t.Fatal("want an error dialing a dead address")
}
if !respNotApplied(err) {
t.Errorf("respNotApplied(%v) = false, want true", err)
}
})
t.Run("reply lost after bytes arrived is ambiguous", func(t *testing.T) {
ln := newFakeListener(t)
go func() {
conn, err := ln.Accept()
if err != nil {
return
}
_ = ln.Close()
defer func() { _ = conn.Close() }()
r := bufio.NewReader(conn)
_, _ = readRESPCommand(r) // SELECT
_, _ = conn.Write([]byte("+OK\r\n"))
_, _ = readRESPCommand(r)
_, _ = readRESPCommand(r)
_, _ = conn.Write([]byte(":1\r\n"))
}()
c := newRESPClient(ln.Addr().String(), "", 0)
_, err := c.pipeline(incr)
if err == nil {
t.Fatal("want an error")
}
if respNotApplied(err) {
t.Errorf("respNotApplied(%v) = true, want false: the INCRBY may have landed", err)
}
})
t.Run("timeout after the write is ambiguous", func(t *testing.T) {
ln := newFakeListener(t)
stop := make(chan struct{})
t.Cleanup(func() { close(stop) })
go func() {
conn, err := ln.Accept()
if err != nil {
return
}
defer func() { _ = conn.Close() }()
r := bufio.NewReader(conn)
_, _ = readRESPCommand(r) // SELECT
_, _ = conn.Write([]byte("+OK\r\n"))
_, _ = readRESPCommand(r)
<-stop
}()
c := newRESPClient(ln.Addr().String(), "", 0)
_, err := c.pipeline(incr)
if err == nil {
t.Fatal("want a timeout")
}
if respNotApplied(err) {
t.Errorf("respNotApplied(%v) = true, want false", err)
}
})
t.Run("nil and foreign errors are not marked", func(t *testing.T) {
if respNotApplied(nil) || respNotApplied(fmt.Errorf("boom")) {
t.Error("unmarked error reported as not applied")
}
})
}
func TestRedisStoreKeepsNotAppliedMarker(t *testing.T) {
ln := newFakeListener(t)
addr := ln.Addr().String()
_ = ln.Close()
s := newRedisStore(newRESPClient(addr, "", 0))
entries := []counterIncr{{key: "k", delta: 1, ttl: time.Minute, enforceTTL: time.Minute}}
if _, err := s.incrMulti(entries); err == nil || !respNotApplied(err) {
t.Errorf("incrMulti error %v: respNotApplied = false, want true for a dial failure", err)
}
if _, _, err := s.incrAndGetMulti(entries, nil); err == nil || !respNotApplied(err) {
t.Errorf("incrAndGetMulti error %v: respNotApplied = false, want true for a dial failure", err)
}
}