feat: orchestrate deterministic growth report generation
This commit is contained in:
29
internal/growthreport/coordinator_test.go
Normal file
29
internal/growthreport/coordinator_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package growthreport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCoordinatorFallsBackToBoundedProcessCounters(t *testing.T) {
|
||||
t.Parallel()
|
||||
coordinator := NewCoordinator(nil, CoordinatorConfig{CreatePerMinute: 2, UncachedPerDay: 1, DailyRequests: 1, DailyTokens: 1600, MaxConcurrent: 1})
|
||||
now := time.Date(2026, 8, 21, 0, 0, 0, 0, time.UTC)
|
||||
if err := coordinator.AllowCreate(context.Background(), 7, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := coordinator.AllowCreate(context.Background(), 7, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := coordinator.AllowCreate(context.Background(), 7, now); !errors.Is(err, ErrRateLimited) {
|
||||
t.Fatalf("third request error=%v", err)
|
||||
}
|
||||
if err := coordinator.ReserveBudget(context.Background(), 1600, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := coordinator.ReserveBudget(context.Background(), 1, now); !errors.Is(err, ErrBudgetExhausted) {
|
||||
t.Fatalf("second budget error=%v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user