testorigin

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrDown = errors.New("weir: test origin down")

ErrDown is the transport error every Fetch returns while SetDown(true) is in effect.

View Source
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

func NewChecked(tb testing.TB, maxConcurrent, maxPerPartition int) *Origin

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) Calls

func (o *Origin) Calls(path string) int

Calls returns the number of Fetch calls for path.

func (*Origin) Default

func (o *Origin) Default(b Behavior)

Default sets the behavior for paths without a Route.

func (*Origin) Fetch

func (o *Origin) Fetch(ctx context.Context, req *weir.Request) (*weir.Response, error)

Fetch implements weir.Origin.

func (*Origin) MaxInflight

func (o *Origin) MaxInflight() int

MaxInflight returns the high-water mark of concurrent Fetch calls.

func (*Origin) MaxInflightPartition

func (o *Origin) MaxInflightPartition() int

MaxInflightPartition returns the high-water mark of concurrent Fetch calls for any one partition. The partition is the request path.

func (*Origin) Requests

func (o *Origin) Requests() []*weir.Request

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) Route

func (o *Origin) Route(path string, b Behavior)

Route sets the behavior for an exact path; Default applies otherwise.

func (*Origin) SetDown

func (o *Origin) SetDown(down bool)

SetDown makes every call return ErrDown while down is true.

func (*Origin) TotalCalls

func (o *Origin) TotalCalls() int

TotalCalls returns the number of Fetch calls for all paths.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL