forked from longtao.wu/droboticflow
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestQueryBuildRoundBudgetIsYieldNotSafetyFailure(t *testing.T) {
|
|
now := time.Now()
|
|
r := &queryBuildRound{until: now, now: func() time.Time { return now }}
|
|
err := r.check(t.Context())
|
|
if !errors.Is(err, ErrQueryBuildYielded) || errors.Is(err, ErrQueryReplicaPaused) {
|
|
t.Fatal("round budget became a global safety pause", err)
|
|
}
|
|
ctx, stop := context.WithCancel(t.Context())
|
|
stop()
|
|
if !errors.Is(r.check(ctx), context.Canceled) {
|
|
t.Fatal("shutdown must preserve its cause")
|
|
}
|
|
}
|
|
|
|
func TestQueryBuildBudgetsAreIndependent(t *testing.T) {
|
|
if queryColdRoundBudget == queryRefreshRoundBudget {
|
|
t.Fatal("cold and freshness scheduling budgets coupled")
|
|
}
|
|
for _, cold := range []bool{false, true} {
|
|
r := newQueryBuildRound(cold)
|
|
if err := r.check(t.Context()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if queryBuildOperationBudget >= queryColdRoundBudget {
|
|
t.Fatal("one operation consumed the entire cold round")
|
|
}
|
|
}
|
|
|
|
func TestQueryBuildPacingPreservesCallerCancellation(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(t.Context())
|
|
cancel()
|
|
s := &MongoStore{}
|
|
if err := s.queryBuildPace(ctx, 1024); !errors.Is(err, context.Canceled) || errors.Is(err, ErrQueryBuildYielded) {
|
|
t.Fatal(err)
|
|
}
|
|
}
|