Documentation ¶
Overview ¶
Package chaosclient makes it easy to simulate network latency, misbehaving servers, and random errors from servers. It is intended to stress test components under failure conditions and expose weaknesses in the error handling logic of the codebase.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSimulatedConnectionResetByPeer = Error{errors.New("connection reset by peer")}
ErrSimulatedConnectionResetByPeer emulates the golang net error when a connection is reset by a peer. TODO: make this more accurate TODO: add other error types TODO: add a helper for returning multiple errors randomly.
var LogChaos = ChaosNotifier(logChaos{})
LogChaos is the default ChaosNotifier and writes a message to the Golang log.
Functions ¶
func NewChaosRoundTripper ¶
func NewChaosRoundTripper(rt http.RoundTripper, notify ChaosNotifier, c ...Chaos) http.RoundTripper
NewChaosRoundTripper creates an http.RoundTripper that will intercept requests based on the provided Chaos functions. The notifier is invoked when a Chaos Intercept is fired.
Types ¶
type Chaos ¶
type Chaos interface { // Intercept should return true if the normal flow should be skipped, and the // return response and error used instead. Modifications to the request will // be ignored, but may be used to make decisions about types of failures. Intercept(req *http.Request) (bool, *http.Response, error) }
Chaos intercepts requests to a remote HTTP endpoint and can inject arbitrary failures.
type ChaosFunc ¶
ChaosFunc takes an http.Request and decides whether to alter the response. It returns true if it wishes to mutate the response, with a http.Response or error.
type ChaosNotifier ¶
type ChaosNotifier interface { // OnChaos is invoked when a chaotic outcome was triggered. fn is the // source of Chaos and req was the outgoing request OnChaos(req *http.Request, c Chaos) }
ChaosNotifier notifies another component that the ChaosRoundTripper has simulated a failure.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error returns the nested error when C() is invoked.