Skip to main content

CachedStandaloneCanisterFixturePool

Struct CachedStandaloneCanisterFixturePool 

Source
pub struct CachedStandaloneCanisterFixturePool<B = fn() -> StandaloneCanisterFixture> { /* private fields */ }
Expand description

Caller-owned runtime-capacity pool of independently restorable standalone fixtures.

Each slot owns one PocketIC instance, one installed canister, and one captured baseline snapshot. Acquiring a populated slot restores that snapshot before returning it. At most Self::capacity leases can overlap; a caller waits only when every slot is in use.

One pool owns one fixture builder. The builder must produce the same Wasm, init arguments, topology, and seeded baseline each time it runs. It is not evaluated on a cache hit; use a separate pool for each recipe.

Snapshot restoration rewinds the installed canister, not the surrounding PocketIC instance. Instance time, other canisters, and cycle changes not covered by the selected SnapshotRestoreFunding policy may persist.

The pool contains no process-global state. Downstream suites select a capacity that fits their host and keep lifecycle-sensitive tests on fresh StandaloneCanisterFixture values when snapshot restoration is not the intended isolation boundary.

Implementations§

Source§

impl<B> CachedStandaloneCanisterFixturePool<B>

Source

pub const fn new(capacity: NonZeroUsize, build: B) -> Self

Create a runtime-capacity pool that owns its fixture builder.

Construction is const and lazy: slots are allocated on first acquisition, and the builder runs only when a slot needs a fixture.

use std::num::NonZeroUsize;
use ic_testkit::pic::{CachedStandaloneCanisterFixturePool, StandaloneCanisterFixture};

static POOL: CachedStandaloneCanisterFixturePool =
    CachedStandaloneCanisterFixturePool::new(
        NonZeroUsize::new(2).unwrap(),
        build_fixture,
    );

// Local pools can choose their capacity at runtime.
let capacity = std::thread::available_parallelism()?;
let pool = CachedStandaloneCanisterFixturePool::new(capacity, build_fixture);
Source

pub const fn capacity(&self) -> NonZeroUsize

Maximum number of simultaneously leased standalone fixtures.

Source

pub const fn with_restore_funding(self, funding: SnapshotRestoreFunding) -> Self

Select the cycle-funding policy applied immediately before each snapshot restore.

Source

pub fn acquire( &self, ) -> Result<(CachedStandaloneCanisterFixtureGuard<'_>, StandaloneFixturePoolOutcome), StandaloneFixturePoolError>

Acquire one isolated fixture, building a slot on first use and restoring its captured snapshot on later uses.

The pool’s builder runs only when an empty or invalid slot is populated or a dead PocketIC instance must be replaced.

A recognized dead-instance transport failure evicts and rebuilds only the affected slot. Other snapshot failures are returned unchanged and invalidate the possibly partially restored slot for the next lease.

Acquire one fixture with a structured lifecycle outcome and phase timings.

§Errors

Returns the failed preparation stage, the structured snapshot error, and all phase timings completed before failure. If dead-transport restoration and replacement capture both fail, both errors are retained.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more