Document invocation observation and cost reporting
This commit is contained in:
@@ -112,6 +112,35 @@ func TestInjectedFailedResponseCostIsObservedOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanceledDispatchCostFallbackAndUndispatchedEmptyCost(t *testing.T) {
|
||||
configured := testCoordinator(t, func(*http.Request) (*http.Response, error) { t.Fatal("unexpected HTTP"); return nil, nil })
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
coordinator := NewInjected(configured.manager, cancelingCostClient{cancel: cancel})
|
||||
var cost observation.CostAccumulator
|
||||
req := testRequest(0)
|
||||
req.Target.ZeroCost = true
|
||||
if _, err := coordinator.Generate(observation.WithCostAccumulator(ctx, &cost), req); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("dispatch error=%v", err)
|
||||
}
|
||||
if got := cost.Observed(); got != (domain.ObservedCost{Known: true, Complete: true, Source: domain.CostSourceConfiguredZero}) {
|
||||
t.Fatalf("dispatched=%+v", got)
|
||||
}
|
||||
var untouched observation.CostAccumulator
|
||||
if _, err := coordinator.Generate(observation.WithCostAccumulator(ctx, &untouched), req); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("pre-dispatch error=%v", err)
|
||||
}
|
||||
if got := untouched.Observed(); got != (domain.ObservedCost{Known: true, Complete: true}) {
|
||||
t.Fatalf("undispatched=%+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
type cancelingCostClient struct{ cancel context.CancelFunc }
|
||||
|
||||
func (c cancelingCostClient) Generate(ctx context.Context, _ domain.GenerateRequest) (*domain.GenerateResponse, error) {
|
||||
c.cancel()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
|
||||
func TestObservedInterruptedWaitAndCanceledCapacity(t *testing.T) {
|
||||
coordinator := testCoordinator(t, func(*http.Request) (*http.Response, error) { return response(503, `{"error":{}}`), nil })
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user