Skip to main content

Crate ic_call_chaos

Crate ic_call_chaos 

Source
Expand description

Chaos testing library for Internet Computer inter-canister calls

ic_call_chaos is a small library to enable testing the resilience of Internet Computer canisters to inter-canister call failures. It allows you to simulate various failure scenarios, such as dropped, timed out, or rejected calls, to ensure that your canisters can handle these situations gracefully.

It is designed to be used in conjunction with the ic-cdk library, which provides the necessary tools for building canisters on the Internet Computer.

§Usage

  1. Import Call and friends from ic_call_chaos instead of ic_cdk::call. The provided interface is the same as ic_cdk::call, but with additional functionality to simulate failures. The default policy is AllowAll, which means that all calls will be passed to the underlying ic_cdk library. You likely want to make the replacement import conditional on a feature flag, so that you don’t inherit the overhead of (or any bugs in) the wrapper in production.
  2. Provide a way to change the failure policy from tests.
  3. In your tests, apply the desired policy.

For examples, look at the source of this library, and in particular canister/src/lib.rs for an example of how to add ic_call_chaos to your canister code, and pocket_ic_test/tests/integration_test.rs for an example of how to use it in your tests.

Structs§

AllowAll
A simple policy that allows all calls.
AllowEveryOther
A simple policy that fails every other call with a SysTransient reject code.
Call
A wrapper around ic_cdk::call::Call that enables “chaos testing” by failing calls according to a policy set by set_policy. It’s implemented as a drop-in replacement for ic_cdk::call::Call, so it can be used in lieu of it by simple changing imports. See the documentation on ic_cdk::call::Call for more details on the individual methods.
CallFuture
DenyAll
A simple policy that denies all calls, returning a SysTransient reject code.
WithProbability
A policy that allows calls with a given probability. The probability is a float between 0 and 1. For bounded wait calls, if silently_perform_bounded_wait_calls is set to true, bounded-wat calls A will be executed though a reject code (SysUnknown) will be returned. This is useful for simulating timeouts in production.

Enums§

CallType

Traits§

Policy
A trait that defines a policy for allowing or rejecting calls.

Functions§

set_policy