pub struct WorkerEmulator { /* private fields */ }Expand description
Web Worker emulator for testing message passing and state transitions
Implements Lamport (1978) message ordering guarantees for verification.
§Example
use jugar_probar::capabilities::{WorkerEmulator, WorkerMessage, WorkerState};
let mut emulator = WorkerEmulator::new();
emulator.spawn("audio_processor");
// Simulate worker initialization
emulator.send(WorkerMessage::new("Init", serde_json::json!({"model": "tiny"})));
assert_eq!(emulator.state(), WorkerState::Loading);
emulator.receive_response(WorkerMessage::new("Ready", serde_json::json!({})));
assert_eq!(emulator.state(), WorkerState::Ready);Implementations§
Source§impl WorkerEmulator
impl WorkerEmulator
Sourcepub fn state(&self) -> WorkerState
pub fn state(&self) -> WorkerState
Get current worker state
Sourcepub fn send(&mut self, message: WorkerMessage)
pub fn send(&mut self, message: WorkerMessage)
Send a message to the worker
Sourcepub fn receive_response(&mut self, response: WorkerMessage)
pub fn receive_response(&mut self, response: WorkerMessage)
Receive a response from the worker
Sourcepub fn pending_messages(&self) -> &[WorkerMessage]
pub fn pending_messages(&self) -> &[WorkerMessage]
Get pending messages
Sourcepub fn responses(&self) -> &[WorkerMessage]
pub fn responses(&self) -> &[WorkerMessage]
Get received responses
Sourcepub fn lamport_time(&self) -> u64
pub fn lamport_time(&self) -> u64
Get current Lamport timestamp
Sourcepub fn with_delays(self, enable: bool) -> Self
pub fn with_delays(self, enable: bool) -> Self
Enable delay simulation
Sourcepub fn verify_ordering(&self) -> bool
pub fn verify_ordering(&self) -> bool
Verify message ordering (Lamport guarantee)
Returns true if all messages maintain causal ordering.
Sourcepub fn assert_state(&self, expected: WorkerState) -> Result<(), CapabilityError>
pub fn assert_state(&self, expected: WorkerState) -> Result<(), CapabilityError>
Sourcepub fn interception_js() -> &'static str
pub fn interception_js() -> &'static str
Generate JavaScript to intercept Worker constructor
Trait Implementations§
Source§impl Clone for WorkerEmulator
impl Clone for WorkerEmulator
Source§fn clone(&self) -> WorkerEmulator
fn clone(&self) -> WorkerEmulator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WorkerEmulator
impl Debug for WorkerEmulator
Auto Trait Implementations§
impl Freeze for WorkerEmulator
impl RefUnwindSafe for WorkerEmulator
impl Send for WorkerEmulator
impl Sync for WorkerEmulator
impl Unpin for WorkerEmulator
impl UnsafeUnpin for WorkerEmulator
impl UnwindSafe for WorkerEmulator
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().