Documentation
¶
Overview ¶
Package testorigin is a programmable weir.Origin for engine and load tests (docs/07-testing-strategy.md §3). Every wait blocks on channels or timers, so behaviors take fake time inside a synctest bubble.
Index ¶
- Variables
- type Behavior
- type Origin
- func (o *Origin) Calls(path string) int
- func (o *Origin) Default(b Behavior)
- func (o *Origin) Fetch(ctx context.Context, req *weir.Request) (*weir.Response, error)
- func (o *Origin) MaxInflight() int
- func (o *Origin) MaxInflightPartition() int
- func (o *Origin) Requests() []*weir.Request
- func (o *Origin) Reset()
- func (o *Origin) Route(path string, b Behavior)
- func (o *Origin) SetDown(down bool)
- func (o *Origin) TotalCalls() int
Constants ¶
This section is empty.
Variables ¶
var ErrBodyClosed = errors.New("weir: test origin read on closed body")
ErrBodyClosed is returned by a response body Read after Close, as net/http does.
var ErrDown = errors.New("weir: test origin down")
ErrDown is the transport error every Fetch returns while SetDown(true) is in effect.
var ErrOverConcurrency = errors.New("weir: test origin over concurrency bound")
ErrOverConcurrency is returned by a checked Origin's Fetch when the call would exceed a concurrency bound.
Functions ¶
This section is empty.
Types ¶
type Behavior ¶
type Behavior struct {
Status int // 0 means 200
Header http.Header
Body []byte
Delay time.Duration // before headers; fake time under synctest
Gate <-chan struct{} // if set, block until closed or ctx done
Err error // return as a transport error
Panic bool
Truncate int // body read fails after this many bytes (0 = off)
BodyDelay time.Duration // delay between header and body bytes
Func func(*weir.Request) (*weir.Response, error) // full control
}
Behavior is how the origin answers one path. Steps run in field order: Delay, Gate, Err, Panic, then Func or the static response. Func's response is returned as is: Status, Header, Body, Truncate and BodyDelay do not apply to it.
type Origin ¶
type Origin struct {
// contains filtered or unexported fields
}
Origin is a programmable weir.Origin. It is safe for concurrent use.
func New ¶
func New() *Origin
New returns an Origin that answers 200 with an empty body until configured.
func NewChecked ¶
NewChecked returns an Origin that asserts INV-7 on every call: a Fetch that would put more than maxConcurrent calls in flight, or more than maxPerPartition for one path, fails tb and returns ErrOverConcurrency. Both bounds must be at least 1; a bound of 0 rejects every call.
func (*Origin) MaxInflight ¶
MaxInflight returns the high-water mark of concurrent Fetch calls.
func (*Origin) MaxInflightPartition ¶
MaxInflightPartition returns the high-water mark of concurrent Fetch calls for any one partition. The partition is the request path.
func (*Origin) Requests ¶
Requests returns every request Fetch received, in call order, for INV-1 checks. Each is a copy taken at call time with a cloned Header.
func (*Origin) Reset ¶
func (o *Origin) Reset()
Reset clears call counts, high-water marks and recorded requests. Routes, the default and the down state stay.
func (*Origin) TotalCalls ¶
TotalCalls returns the number of Fetch calls for all paths.