v1 proxy test: order arrivals by limiter state; note the 499-on-served-200 defect for v2.1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,19 @@ func TestDifferentConversationsSpreadByFreeSlots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// waitUntil polls cond every 5 ms for up to two seconds and fails the test if it never holds.
|
||||
func waitUntil(t *testing.T, cond func() bool) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
if cond() {
|
||||
return
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
t.Fatal("condition not reached within two seconds")
|
||||
}
|
||||
|
||||
func TestQueueFullIs503(t *testing.T) {
|
||||
alpha := newUpstream(t, "alpha")
|
||||
alpha.delay = 400 * time.Millisecond
|
||||
@@ -99,14 +112,20 @@ hosts = ["alpha"]
|
||||
default_model = "shared"
|
||||
`, alpha)
|
||||
codes := make(chan int, 3)
|
||||
for i := 1; i <= 3; i++ {
|
||||
go func(i int) {
|
||||
fire := func(i int) {
|
||||
go func() {
|
||||
resp := r.post("/r/v1/chat/completions", conversation(i, 1))
|
||||
drain(resp)
|
||||
codes <- resp.StatusCode
|
||||
}(i)
|
||||
time.Sleep(30 * time.Millisecond) // arrival order: 1 runs, 2 queues, 3 finds the queue full
|
||||
}()
|
||||
}
|
||||
// Arrival order is enforced by watching the limiter, not by sleeping: 1 runs, 2 queues,
|
||||
// 3 finds the queue full.
|
||||
fire(1)
|
||||
waitUntil(t, func() bool { return r.lim.InFlight("alpha", "shared") == 1 })
|
||||
fire(2)
|
||||
waitUntil(t, func() bool { return r.lim.Queued("alpha", "shared") == 1 })
|
||||
fire(3)
|
||||
got := map[int]int{}
|
||||
for i := 0; i < 3; i++ {
|
||||
got[<-codes]++
|
||||
|
||||
Reference in New Issue
Block a user