mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-08 04:06:18 -04:00
fix(#76): prevent false-fresh aggregate responses
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user