Files
traefik-llmgateway/timeout_record_order_test.go
lukaszraczyloandGitHub f1b198bce4 fix(security): audit run-4 fixes and run-3 leftovers (#26)
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
2026-11-29 10:50:36 +00:00

30 lines
762 B
Go

package traefikllmgateway
import (
"context"
"io"
"net/http"
"strings"
"testing"
"time"
)
// A reader unblocked by the watchdog's cancel must find the failure already recorded.
func TestWatchdogFire_RecordsTimeoutBeforeCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cancelledAtRecord := make(chan bool, 1)
rec := func(_ *http.Response, _ error) {
time.Sleep(20 * time.Millisecond)
cancelledAtRecord <- ctx.Err() != nil
}
wb := newWatchdogBody(io.NopCloser(strings.NewReader("")), cancel, time.Hour, "p1", rec)
wb.fire()
if <-cancelledAtRecord {
t.Fatal("context was cancelled before onTimeout recorded the failure")
}
if ctx.Err() == nil {
t.Fatal("context not cancelled after fire")
}
}