Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
82 lines
2.9 KiB
Go
82 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWikiProviderCircuitScopeAndExpiry(t *testing.T) {
|
|
s := &wikiIngestService{}
|
|
ctx := context.Background()
|
|
key := wikiProviderCircuitKey(1, t.Name())
|
|
t.Cleanup(func() { wikiProviderBlocks.Delete(key) })
|
|
s.blockWikiProvider(ctx, key, errors.New("API request failed with status 402: private provider text"))
|
|
if err := s.checkWikiProvider(ctx, key); err == nil {
|
|
t.Fatal("billing failure must block further requests")
|
|
}
|
|
if err := s.checkWikiProvider(ctx, wikiProviderCircuitKey(2, t.Name())); err != nil {
|
|
t.Fatal("different tenant blocked", err)
|
|
}
|
|
if err := s.checkWikiProvider(ctx, wikiProviderCircuitKey(1, "another-model")); err != nil {
|
|
t.Fatal("different model blocked", err)
|
|
}
|
|
wikiProviderBlocks.Store(key, wikiProviderBlock{status: 402, until: time.Now().Add(-time.Second)})
|
|
if err := s.checkWikiProvider(ctx, key); err != nil {
|
|
t.Fatal("expired block should allow a new attempt", err)
|
|
}
|
|
}
|
|
|
|
func TestWikiProviderCircuitDoesNotBlockTransientOrOutputErrors(t *testing.T) {
|
|
s := &wikiIngestService{}
|
|
key := wikiProviderCircuitKey(1, t.Name())
|
|
t.Cleanup(func() { wikiProviderBlocks.Delete(key) })
|
|
for _, message := range []string{"API request failed with status 503", "invalid JSON: 402"} {
|
|
s.blockWikiProvider(context.Background(), key, errors.New(message))
|
|
if err := s.checkWikiProvider(context.Background(), key); err != nil {
|
|
t.Fatalf("unexpected block for %s", message)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWikiProviderRateLimitUsesShortCooldown(t *testing.T) {
|
|
s := &wikiIngestService{}
|
|
key := wikiProviderCircuitKey(1, t.Name())
|
|
t.Cleanup(func() { wikiProviderBlocks.Delete(key) })
|
|
s.blockWikiProvider(context.Background(), key, errors.New("API request failed with status 429"))
|
|
if err := s.checkWikiProvider(context.Background(), key); err == nil || !isLikelyRateLimitError(err) {
|
|
t.Fatalf("rate limit must be blocked and retain its classification: %v", err)
|
|
}
|
|
value, _ := wikiProviderBlocks.Load(key)
|
|
remaining := time.Until(value.(wikiProviderBlock).until)
|
|
if remaining <= 0 || remaining > time.Minute {
|
|
t.Fatalf("unexpected rate limit cooldown: %s", remaining)
|
|
}
|
|
}
|
|
|
|
func TestWikiProviderSlotsBoundParallelismAndHonorCancellation(t *testing.T) {
|
|
key := wikiProviderCircuitKey(1, t.Name())
|
|
t.Cleanup(func() { wikiProviderSlots.Delete(key) })
|
|
first, err := acquireWikiProviderSlot(context.Background(), key)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer first()
|
|
second, err := acquireWikiProviderSlot(context.Background(), key)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer second()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
|
defer cancel()
|
|
if release, err := acquireWikiProviderSlot(ctx, key); release != nil || !errors.Is(err, context.DeadlineExceeded) {
|
|
t.Fatalf("third call bypassed concurrency limit: %v", err)
|
|
}
|
|
other, err := acquireWikiProviderSlot(context.Background(), wikiProviderCircuitKey(2, t.Name()))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
other()
|
|
}
|