mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
30 lines
762 B
Go
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")
|
|
}
|
|
}
|