pub struct CachedPocketIcBaselinePool<R>where
R: PocketIcBaselineRecipe,{ /* private fields */ }Expand description
Caller-owned runtime-capacity pool of independently restorable PocketIC baselines.
One pool structurally owns one PocketIcBaselineRecipe. A warm
acquisition restores the complete captured canister set, applies the
recipe’s non-snapshot reset, reaches its readiness boundary, checks typed
reset coverage, and validates final invariants before exposing a lease.
Each capacity slot owns an independent PocketIC instance.
Snapshot reuse is not a complete PocketIC rollback. The recipe must account
for time, extra canisters, pending messages, subnet state, cycles, and
external resources when those domains matter to its tests.
Implementations§
Source§impl<R> CachedPocketIcBaselinePool<R>where
R: PocketIcBaselineRecipe,
impl<R> CachedPocketIcBaselinePool<R>where
R: PocketIcBaselineRecipe,
Sourcepub const fn new(capacity: NonZeroUsize, recipe: R) -> Self
pub const fn new(capacity: NonZeroUsize, recipe: R) -> Self
Create a runtime-capacity pool that structurally owns one recipe.
Construction is const and lazy: slots are allocated on first acquisition, and the recipe builds a baseline only when a slot needs one.
Sourcepub async fn close(self) -> Vec<ClientError>
pub async fn close(self) -> Vec<ClientError>
Consume the pool and await Self::shutdown, retaining every deletion failure.
Sourcepub async fn shutdown(&self) -> Vec<ClientError>
pub async fn shutdown(&self) -> Vec<ClientError>
Stop admission, await all leases, and attempt every cached instance deletion.
Works through a shared or static reference. Acquisitions after shutdown
begins return BaselinePoolError::Closed; queued acquisitions cannot
prepare another baseline. Already exposed leases remain usable until
their guards are dropped. Do not await shutdown while holding a lease
in the same task. Borrowed server owners must outlive this operation.
Deletion failures do not stop remaining deletions. Concurrent shutdowns serialize; each call returns its own failures, and completed attempts are never replayed. The caller must inspect every returned error.
Cancellation leaves admission closed and retains unattempted baselines for a later shutdown. An in-flight deletion has an unknown outcome and requires caller reconciliation; it is not retried. Rust Drop performs no client network I/O.
Sourcepub const fn capacity(&self) -> NonZeroUsize
pub const fn capacity(&self) -> NonZeroUsize
Maximum number of simultaneously leased PocketIC baselines.
Sourcepub async fn acquire(
&self,
) -> Result<(CachedPocketIcBaselinePoolGuard<'_, R>, BaselinePoolOutcome), BaselinePoolError<R::Error>>
pub async fn acquire( &self, ) -> Result<(CachedPocketIcBaselinePoolGuard<'_, R>, BaselinePoolOutcome), BaselinePoolError<R::Error>>
Acquire one fully built or restored and validated baseline lease.
A rebuildable warm-preparation failure discards the stale slot and performs at most one build attempt. Recipe and caller panics are never converted into cache misses; the lease is invalidated while the panic continues unwinding.
§Errors
Returns a stage-specific recipe or contract error. If warm preparation and its one recovery build both fail, the error preserves both causes.