From 58ea61af68756cdabb4aead652b09818e01b3728 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 8 Sep 2025 15:41:20 +0200 Subject: [PATCH] Remove more todos --- crates/gpui/src/executor2.rs | 12 ++++-------- crates/scheduler/src/test_scheduler.rs | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/gpui/src/executor2.rs b/crates/gpui/src/executor2.rs index 770927bc8a..63db4d1cc7 100644 --- a/crates/gpui/src/executor2.rs +++ b/crates/gpui/src/executor2.rs @@ -212,22 +212,19 @@ impl BackgroundExecutor { /// do take real async time to run. #[cfg(any(test, feature = "test-support"))] pub fn allow_parking(&self) { - // self.0.allow_parking() - todo!() + self.0.scheduler().as_test().allow_parking(); } /// undoes the effect of [`Self::allow_parking`]. #[cfg(any(test, feature = "test-support"))] pub fn forbid_parking(&self) { - // self.0.forbid_parking() - todo!() + self.0.scheduler().as_test().forbid_parking(); } /// in tests, returns the rng used by the dispatcher and seeded by the `SEED` environment variable #[cfg(any(test, feature = "test-support"))] pub fn rng(&self) -> StdRng { - // self.0.rng() - todo!() + self.scheduler().as_test().rng().lock().clone() } /// How many CPUs are available for this executor. @@ -242,8 +239,7 @@ impl BackgroundExecutor { #[cfg(any(test, feature = "test-support"))] /// in tests, control the number of ticks that `block_with_timeout` will run before timing out. pub fn set_block_on_ticks(&self, range: std::ops::RangeInclusive) { - // self.0.set_block_on_ticks(range) - todo!() + self.0.scheduler().as_test().set_timeout_ticks(range) } } diff --git a/crates/scheduler/src/test_scheduler.rs b/crates/scheduler/src/test_scheduler.rs index e0a860aeb0..b9e6f8f034 100644 --- a/crates/scheduler/src/test_scheduler.rs +++ b/crates/scheduler/src/test_scheduler.rs @@ -13,6 +13,7 @@ use std::{ fmt::Write, future::Future, mem, + ops::RangeInclusive, panic::{self, AssertUnwindSafe}, pin::Pin, sync::{ @@ -69,7 +70,7 @@ impl TestScheduler { blocked_sessions: Vec::new(), randomize_order: config.randomize_order, allow_parking: config.allow_parking, - max_timeout_ticks: config.max_timeout_ticks, + timeout_ticks: config.timeout_ticks, next_session_id: SessionId(0), pending_traces: BTreeMap::new(), next_trace_id: TraceId(0), @@ -86,6 +87,14 @@ impl TestScheduler { self.rng.clone() } + pub fn set_timeout_ticks(&self, timeout_ticks: RangeInclusive) { + self.state.lock().timeout_ticks = timeout_ticks; + } + + pub fn allow_parking(&self) { + self.state.lock().allow_parking = true; + } + pub fn forbid_parking(&self) { self.state.lock().allow_parking = false; } @@ -187,7 +196,7 @@ impl Scheduler for TestScheduler { let max_ticks = if timeout.is_some() { self.rng .lock() - .random_range(0..=self.state.lock().max_timeout_ticks) + .random_range(self.state.lock().timeout_ticks.clone()) } else { usize::MAX }; @@ -297,7 +306,7 @@ pub struct TestSchedulerConfig { pub seed: u64, pub randomize_order: bool, pub allow_parking: bool, - pub max_timeout_ticks: usize, + pub timeout_ticks: RangeInclusive, } impl TestSchedulerConfig { @@ -315,7 +324,7 @@ impl Default for TestSchedulerConfig { seed: 0, randomize_order: true, allow_parking: false, - max_timeout_ticks: 1000, + timeout_ticks: 0..=1000, } } } @@ -342,7 +351,7 @@ struct SchedulerState { blocked_sessions: Vec, randomize_order: bool, allow_parking: bool, - max_timeout_ticks: usize, + timeout_ticks: RangeInclusive, next_session_id: SessionId, next_trace_id: TraceId, pending_traces: BTreeMap,