Files
traefik-llmgateway/concurrency_test.go
T
lukaszraczylo cbffcb4061 fix(concurrency): clamp learned limit below the ceiling
An overload seen with many requests in flight set the learned limit above the ceiling. The learner now clamps the value to one below the ceiling.
2026-11-02 23:57:07 +00:00

37 lines
985 B
Go

package traefikllmgateway
import (
"net/http"
"testing"
)
// TestConcurrencyLearner_OverloadStaysBelowCeiling pins that an overload
// observation on an unknown limit never learns a value at or above the
// ceiling, however many requests were in flight.
func TestConcurrencyLearner_OverloadStaysBelowCeiling(t *testing.T) {
t.Parallel()
tests := []struct {
name string
inFlight int
}{
{name: "one in flight", inFlight: 1},
{name: "typical load", inFlight: 8},
{name: "exactly at ceiling", inFlight: 2 * learnedCeiling},
{name: "far above ceiling", inFlight: 1000},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := newConcurrencyLearner(0)
for range tt.inFlight {
_ = c.begin("p")
}
c.observe("p", &http.Response{StatusCode: http.StatusTooManyRequests}, nil)
got := c.limit("p")
if got < 1 || got > learnedCeiling-1 {
t.Errorf("limit = %d, want in [1, %d]", got, learnedCeiling-1)
}
})
}
}