fix(#76): prevent false-fresh aggregate responses

This commit is contained in:
2026-07-12 20:50:18 -04:00
parent 01d291507d
commit 0bba213652
15 changed files with 620 additions and 110 deletions

View File

@@ -1,6 +1,7 @@
package api
import (
"context"
"encoding/json"
"io"
"net/http"
@@ -49,6 +50,28 @@ func TestRequestPacerNilSafe(t *testing.T) {
p.wait() // must not panic
}
func TestRequestPacerCancellationReturnsUnusedReservation(t *testing.T) {
p := &requestPacer{interval: 100 * time.Millisecond}
if err := p.waitContext(context.Background()); err != nil {
t.Fatal(err)
}
p.mu.Lock()
wantNext := p.next
p.mu.Unlock()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
defer cancel()
if err := p.waitContext(ctx); err == nil {
t.Fatal("expected paced wait cancellation")
}
p.mu.Lock()
gotNext := p.next
p.mu.Unlock()
if !gotNext.Equal(wantNext) {
t.Fatalf("cancelled reservation left pacing debt: next %v, want %v", gotNext, wantNext)
}
}
func TestGetRetriesOn429(t *testing.T) {
var calls atomic.Int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {