fix: health check includes response body in errors, adds 503 test
Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3c756771ec
commit
d5a92c7212
2 changed files with 16 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -39,7 +40,8 @@ func (c *Client) Health(ctx context.Context) error {
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("llamacpp: health returned %d", resp.StatusCode)
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 256))
|
||||
return fmt.Errorf("llamacpp: health returned %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
var h healthResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&h); err != nil {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@ func TestHealth_NotReady(t *testing.T) {
|
|||
assert.ErrorContains(t, err, "not ready")
|
||||
}
|
||||
|
||||
func TestHealth_Loading(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
w.Write([]byte(`{"error":{"code":503,"message":"Loading model","type":"unavailable_error"}}`))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
c := NewClient(ts.URL)
|
||||
err := c.Health(context.Background())
|
||||
assert.ErrorContains(t, err, "503")
|
||||
}
|
||||
|
||||
func TestHealth_ServerDown(t *testing.T) {
|
||||
c := NewClient("http://127.0.0.1:1") // nothing listening
|
||||
err := c.Health(context.Background())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue