pub struct TestScheduler { /* private fields */ }Implementations§
Source§impl TestScheduler
impl TestScheduler
Sourcepub fn once<R>(f: impl AsyncFnOnce(Arc<TestScheduler>) -> R) -> R
pub fn once<R>(f: impl AsyncFnOnce(Arc<TestScheduler>) -> R) -> R
Run a test once with default configuration (seed 0)
Sourcepub fn many<R>(
default_iterations: usize,
f: impl AsyncFnMut(Arc<TestScheduler>) -> R,
) -> Vec<R>
pub fn many<R>( default_iterations: usize, f: impl AsyncFnMut(Arc<TestScheduler>) -> R, ) -> Vec<R>
Run a test multiple times with sequential seeds (0, 1, 2, …)
pub fn new(config: TestSchedulerConfig) -> Self
pub fn end_test(&self)
pub fn clock(&self) -> Arc<TestClock> ⓘ
pub fn rng(&self) -> SharedRng
pub fn set_timeout_ticks(&self, timeout_ticks: RangeInclusive<usize>)
pub fn allow_parking(&self)
pub fn forbid_parking(&self)
pub fn parking_allowed(&self) -> bool
pub fn is_main_thread(&self) -> bool
pub fn allocate_session_id(&self) -> SessionId
Sourcepub fn foreground(self: &Arc<Self>) -> LocalExecutor
pub fn foreground(self: &Arc<Self>) -> LocalExecutor
Create a local executor for this scheduler.
Sourcepub fn background(self: &Arc<Self>) -> BackgroundExecutor
pub fn background(self: &Arc<Self>) -> BackgroundExecutor
Create a background executor for this scheduler
pub fn yield_random(&self) -> Yield ⓘ
pub fn run(&self)
pub fn run_with_clock_advancement(&self)
Sourcepub fn tick(&self) -> bool
pub fn tick(&self) -> bool
Execute one tick of the scheduler, processing expired timers and running at most one task. Returns true if any work was done.
This is the public interface for GPUI’s TestDispatcher to drive task execution.
Sourcepub fn tick_background_only(&self) -> bool
pub fn tick_background_only(&self) -> bool
Execute one tick, but only run background tasks (no foreground/session tasks). Returns true if any work was done.
Sourcepub fn has_pending_tasks(&self) -> bool
pub fn has_pending_tasks(&self) -> bool
Check if there are any pending tasks or timers that could run.
Sourcepub fn pending_task_counts(&self) -> (usize, usize)
pub fn pending_task_counts(&self) -> (usize, usize)
Returns counts of (foreground_tasks, background_tasks) currently queued. Foreground tasks are those with a session_id, background tasks have none.
Sourcepub fn drain_tasks(&self)
pub fn drain_tasks(&self)
Drops all runnable tasks from the scheduler.
This is used by the leak detector to ensure that all tasks have been dropped as tasks may keep entities alive otherwise. Why do we even have tasks left when tests finish you may ask. The reason for that is simple, the scheduler itself is the executor and it retains the scheduled runnables. A lot of tasks, including every foreground task contain an executor handle that keeps the test scheduler alive, causing a reference cycle, thus the need for this function right now.
pub fn advance_clock_to_next_timer(&self) -> bool
pub fn advance_clock(&self, duration: Duration)
Trait Implementations§
Source§impl Scheduler for TestScheduler
impl Scheduler for TestScheduler
Source§fn block(
&self,
session_id: Option<SessionId>,
future: Pin<&mut dyn Future<Output = ()>>,
timeout: Option<Duration>,
) -> bool
fn block( &self, session_id: Option<SessionId>, future: Pin<&mut dyn Future<Output = ()>>, timeout: Option<Duration>, ) -> bool
Block until the given future completes, with an optional timeout. If the future is unable to make progress at any moment before the timeout and no other tasks or timers remain, we panic unless parking is allowed. If parking is allowed, we block up to the timeout or indefinitely if none is provided. This is to allow testing a mix of deterministic and non-deterministic async behavior, such as when interacting with I/O in an otherwise deterministic test.
Source§fn spawn_dedicated(
self: Arc<Self>,
f: Box<dyn FnOnce(LocalExecutor) -> Pin<Box<dyn Future<Output = Box<dyn Any + Send + Sync>> + 'static>> + Send + 'static>,
) -> Task<Box<dyn Any + Send + Sync>> ⓘ
fn spawn_dedicated( self: Arc<Self>, f: Box<dyn FnOnce(LocalExecutor) -> Pin<Box<dyn Future<Output = Box<dyn Any + Send + Sync>> + 'static>> + Send + 'static>, ) -> Task<Box<dyn Any + Send + Sync>> ⓘ
In the test world, dedicated work is just a fresh local session driven
by the test scheduler’s run loop alongside everything else. No real
thread is spawned, so determinism under TestScheduler::many is
preserved.
Source§fn schedule_local(
&self,
session_id: SessionId,
runnable: Runnable<RunnableMeta>,
)
fn schedule_local( &self, session_id: SessionId, runnable: Runnable<RunnableMeta>, )
session_id.
Runnables scheduled here run in order on whichever thread drains the
session — the main thread for ordinary sessions, or a dedicated OS
thread for sessions created via spawn_dedicated_thread.