pub struct Mocker<K: KernelInterface> { /* private fields */ }Expand description
Native test harness for running one block without a Runtime.
Mocker wraps a kernel in the same block wrapper used by the runtime, but
drives init, work, message handlers, and deinit directly. It is useful
for focused unit tests and microbenchmarks where constructing a full
Flowgraph would add noise.
Implementations§
Source§impl<K: KernelInterface + Kernel + 'static> Mocker<K>
impl<K: KernelInterface + Kernel + 'static> Mocker<K>
Sourcepub fn parts_mut(&mut self) -> (&mut K, &mut MessageOutputs, &mut BlockMeta)
pub fn parts_mut(&mut self) -> (&mut K, &mut MessageOutputs, &mut BlockMeta)
Get mutable access to the wrapped kernel state used by Kernel::work.
Sourcepub fn new(kernel: K) -> Self
pub fn new(kernel: K) -> Self
Create a mocker around one kernel instance.
Message output ports declared by the block are connected to internal
sinks so tests can inspect emitted PMTs with Mocker::messages or
Mocker::take_messages.
Sourcepub fn post(&mut self, id: impl Into<PortId>, p: Pmt) -> Result<Pmt, Error>
pub fn post(&mut self, id: impl Into<PortId>, p: Pmt) -> Result<Pmt, Error>
Call one message handler of the block and return its PMT result.
This executes the generated handler dispatch directly. It does not run
work() afterward; call Mocker::run if the handler only queued state
that should be processed by the work loop.
Sourcepub fn run(&mut self)
pub fn run(&mut self)
Run the block’s work() loop synchronously.
The loop repeats while the block sets WorkIo::call_again. Message
outputs produced during each call are captured before the next iteration.
Sourcepub fn take_messages(&mut self) -> Vec<Vec<Pmt>>
pub fn take_messages(&mut self) -> Vec<Vec<Pmt>>
Take produced PMTs from output message ports.
Sourcepub async fn run_async(&mut self)
pub async fn run_async(&mut self)
Run the block’s work() loop asynchronously.
Like Mocker::run, this repeats while WorkIo::call_again is set.
Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for Mocker<K>where
K: Freeze,
impl<K> !RefUnwindSafe for Mocker<K>
impl<K> Send for Mocker<K>where
K: Send,
impl<K> Sync for Mocker<K>where
K: Sync,
impl<K> Unpin for Mocker<K>where
K: Unpin,
impl<K> UnsafeUnpin for Mocker<K>where
K: UnsafeUnpin,
impl<K> !UnwindSafe for Mocker<K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Renamed to random to avoid conflict with the new gen keyword in Rust 2024.
Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Renamed to random_range
Rng::random_range.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore to a RngReadAdapter.