diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index c05cf5745d6e19172191e298fa4f31e76513a00b..c8c5df09e557e5bfd585a77ab6f6a47e25b31c52 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -315,10 +315,8 @@ impl BackgroundExecutor { "parked with nothing left to run{waiting_message}{backtrace_message}", ) } - dispatcher.set_unparker(unparker.clone()); - parker.park_timeout( - test_should_end_by.saturating_duration_since(Instant::now()), - ); + dispatcher.push_unparker(unparker.clone()); + parker.park_timeout(Duration::from_millis(1)); if Instant::now() > test_should_end_by { panic!("test timed out after {duration:?} with allow_parking") } diff --git a/crates/gpui/src/platform/test/dispatcher.rs b/crates/gpui/src/platform/test/dispatcher.rs index 017c29bfb558f77874a9729a52b518d9d41fb256..e115f1c07af81f6ad49de29fdad5fb7a432101bf 100644 --- a/crates/gpui/src/platform/test/dispatcher.rs +++ b/crates/gpui/src/platform/test/dispatcher.rs @@ -39,7 +39,7 @@ struct TestDispatcherState { waiting_backtrace: Option, deprioritized_task_labels: HashSet, block_on_ticks: RangeInclusive, - last_parked: Option, + unparkers: Vec, } impl TestDispatcher { @@ -59,7 +59,7 @@ impl TestDispatcher { waiting_backtrace: None, deprioritized_task_labels: Default::default(), block_on_ticks: 0..=1000, - last_parked: None, + unparkers: Default::default(), }; TestDispatcher { @@ -240,20 +240,14 @@ impl TestDispatcher { let block_on_ticks = lock.block_on_ticks.clone(); lock.random.random_range(block_on_ticks) } - pub fn unpark_last(&self) { - self.state - .lock() - .last_parked - .take() - .as_ref() - .map(Unparker::unpark); + + pub fn unpark_all(&self) { + self.state.lock().unparkers.retain(|parker| parker.unpark()); } - pub fn set_unparker(&self, unparker: Unparker) { - let last = { self.state.lock().last_parked.replace(unparker) }; - if let Some(last) = last { - last.unpark(); - } + pub fn push_unparker(&self, unparker: Unparker) { + let mut state = self.state.lock(); + state.unparkers.push(unparker); } } @@ -286,7 +280,7 @@ impl PlatformDispatcher for TestDispatcher { state.background.push(runnable); } } - self.unpark_last(); + self.unpark_all(); } fn dispatch_on_main_thread(&self, runnable: Runnable) { @@ -296,7 +290,7 @@ impl PlatformDispatcher for TestDispatcher { .entry(self.id) .or_default() .push_back(runnable); - self.unpark_last(); + self.unpark_all(); } fn dispatch_after(&self, duration: std::time::Duration, runnable: Runnable) {