Chaos strategies make a healthy dependency look broken, on purpose and at a controlled rate. Use them to check that the rest of the pipeline does its job: that the retry really retries, the timeout fires, the breaker opens and the fallback answers. Run them in tests, staging, and carefully in production. They are a port of Polly’s Simmy, with the same option and event names. Don’t use them as a test double for business logic; a mock is simpler.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
Add chaos strategies last (innermost), right before the callback, so every strategy you want to test sees the injected failure as if it came from the dependency.
Each execution: if enabled, draw randomizer(); inject when it’s below the injection rate. A generator that returns undefined (fault or outcome) skips injection for that call. An abort during injected latency fails the execution with the abort reason.
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
ResiliencePipelineBuilder,
classTimeoutRejectedError
TimeoutRejectedError,
functionweighted<V>(entries:ReadonlyArray<{
readonlyweight:number;
readonlyvalue:V| (() =>V);
}>, randomizer?: () =>number): () =>V
Picks one of several faults/outcomes by weight (Polly's FaultGenerator / OutcomeGenerator):
faultGenerator: weighted([{ weight: 80, value: () => new TimeoutError() }, { weight: 20, value: () => new Error('500') }]).
Values may be factories (called per injection) or constants.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
ResiliencePipelineBuilder<
interfaceResponse
The Response interface of the Fetch API represents the response to a request.
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Picks one of several faults/outcomes by weight (Polly's FaultGenerator / OutcomeGenerator):
faultGenerator: weighted([{ weight: 80, value: () => new TimeoutError() }, { weight: 20, value: () => new Error('500') }]).
Values may be factories (called per injection) or constants.
weighted(entries, randomizer?) returns a function that picks one entry by weight (Polly’s FaultGenerator / OutcomeGenerator). Values may be constants or factories called per pick. Weights must be ≥ 0 and sum to more than 0.
setGlobalChaos(options) injects faults or latency into every pipeline in the process, without touching their configuration. It runs before each callback attempt, so retries and hedges are hit too. Use it for game days and soak tests: “does the whole app survive a slow database?”. It returns a function that turns it off.
Inject faults and/or latency into every pipeline in the process, without touching their configuration:
game days, staging soak tests, "does my whole app survive a slow database?". Returns a function that turns it off.
Inject faults and/or latency into every pipeline in the process, without touching their configuration:
game days, staging soak tests, "does my whole app survive a slow database?". Returns a function that turns it off.
setGlobalChaos({
GlobalChaosOptions.injectionRate?: number |undefined
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Shared bag for passing data between strategies and the callback.
properties.
Map<string, unknown>.get(key: string): unknown
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
@returns ― Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.