Bound the HTTP timeout regression tests
This commit is contained in:
@@ -1215,11 +1215,9 @@ func TestHandlerDeadlineCancelsBuiltInRetryWait(t *testing.T) {
|
||||
}))
|
||||
defer provider.Close()
|
||||
h := newRetryHandler(t, provider.URL+"/v1", intPointer(1), 0, nil)
|
||||
failures := observeRunnerFailures(h)
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p","run_timeout_seconds":1}`)))
|
||||
w, err := serveObservedTimeoutRequest(h, `{"prompt_id":"p","run_timeout_seconds":1}`)
|
||||
assertHTTPErrorCode(t, w, http.StatusGatewayTimeout, "deadline_exceeded")
|
||||
if err := <-failures; !errors.Is(err, promptkit.ErrOperationTimeout) {
|
||||
if !errors.Is(err, promptkit.ErrOperationTimeout) {
|
||||
t.Fatalf("engine did not attribute retry wait to operation timeout: %v", err)
|
||||
}
|
||||
if atomic.LoadInt32(&hits) != 1 {
|
||||
@@ -1237,15 +1235,12 @@ func TestHandlerDeadlineDuringBuiltInGeneration(t *testing.T) {
|
||||
defer provider.Close()
|
||||
defer close(release)
|
||||
h := newRetryHandler(t, provider.URL+"/v1", intPointer(0), 0, nil)
|
||||
failures := observeRunnerFailures(h)
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p","run_timeout_seconds":1,"include_execution_report":true}`)))
|
||||
w, err := serveObservedTimeoutRequest(h, `{"prompt_id":"p","run_timeout_seconds":1,"include_execution_report":true}`)
|
||||
select {
|
||||
case <-started:
|
||||
default:
|
||||
t.Fatal("provider call did not start")
|
||||
}
|
||||
err := <-failures
|
||||
if !errors.Is(err, promptkit.ErrOperationTimeout) || !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Errorf("engine did not attribute in-flight generation to operation timeout: %v (deadline cause: %t)", err, errors.Is(err, context.DeadlineExceeded))
|
||||
}
|
||||
@@ -1285,22 +1280,22 @@ func TestHandlerDeadlineCancelsCapacityWaitAndReleasesAdmission(t *testing.T) {
|
||||
}()
|
||||
queue := 1
|
||||
h := newRetryHandler(t, provider.URL+"/v1", intPointer(0), 1, &queue)
|
||||
failures := observeRunnerFailures(h)
|
||||
firstCtx, cancelFirst := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancelFirst()
|
||||
first := httptest.NewRecorder()
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
h.ServeHTTP(first, httptest.NewRequest(http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p"}`)))
|
||||
h.ServeHTTP(first, httptest.NewRequestWithContext(firstCtx, http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p"}`)))
|
||||
}()
|
||||
select {
|
||||
case <-started:
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("first provider call did not start")
|
||||
}
|
||||
waiting := httptest.NewRecorder()
|
||||
h.ServeHTTP(waiting, httptest.NewRequest(http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p","run_timeout_seconds":1}`)))
|
||||
waiting, err := serveObservedTimeoutRequest(h, `{"prompt_id":"p","run_timeout_seconds":1}`)
|
||||
assertHTTPErrorCode(t, waiting, http.StatusGatewayTimeout, "deadline_exceeded")
|
||||
if err := <-failures; !errors.Is(err, promptkit.ErrOperationTimeout) {
|
||||
if !errors.Is(err, promptkit.ErrOperationTimeout) {
|
||||
t.Fatalf("engine did not attribute capacity wait to operation timeout: %v", err)
|
||||
}
|
||||
if atomic.LoadInt32(&hits) != 1 {
|
||||
@@ -1315,24 +1310,25 @@ func TestHandlerDeadlineCancelsCapacityWaitAndReleasesAdmission(t *testing.T) {
|
||||
if first.Code != http.StatusOK {
|
||||
t.Fatalf("first request: status=%d body=%s", first.Code, first.Body.String())
|
||||
}
|
||||
third := httptest.NewRecorder()
|
||||
h.ServeHTTP(third, httptest.NewRequest(http.MethodPost, "/v1/runs", strings.NewReader(`{"prompt_id":"p"}`)))
|
||||
third, _ := serveObservedTimeoutRequest(h, `{"prompt_id":"p"}`)
|
||||
if third.Code != http.StatusOK || atomic.LoadInt32(&hits) != 2 {
|
||||
t.Fatalf("admission was not released: status=%d hits=%d body=%s", third.Code, atomic.LoadInt32(&hits), third.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func observeRunnerFailures(h *Handler) <-chan error {
|
||||
failures := make(chan error, 1)
|
||||
runner := h.runner
|
||||
h.runner = runnerFunc(func(ctx context.Context, request promptkit.RunRequest) (*promptkit.RunResult, error) {
|
||||
result, err := runner.Run(ctx, request)
|
||||
if err != nil {
|
||||
failures <- err
|
||||
}
|
||||
func serveObservedTimeoutRequest(h *Handler, body string) (*httptest.ResponseRecorder, error) {
|
||||
// Bound the test independently of the shorter operation budget under test.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
var runErr error
|
||||
observed := NewHandlerWithOptions(runnerFunc(func(ctx context.Context, request promptkit.RunRequest) (*promptkit.RunResult, error) {
|
||||
result, err := h.runner.Run(ctx, request)
|
||||
runErr = err
|
||||
return result, err
|
||||
})
|
||||
return failures
|
||||
}), h.options)
|
||||
w := httptest.NewRecorder()
|
||||
observed.ServeHTTP(w, httptest.NewRequestWithContext(ctx, http.MethodPost, "/v1/runs", strings.NewReader(body)))
|
||||
return w, runErr
|
||||
}
|
||||
|
||||
func newRetryHandler(t *testing.T, endpoint string, retries *int, concurrency int, queue *int) *Handler {
|
||||
|
||||
Reference in New Issue
Block a user