From e9539476c79a7dacc4013e84962748d4b8fe7ead Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Wed, 4 Oct 2023 20:57:18 -0700 Subject: [PATCH] add test for nested scopes --- crates/bevy_tasks/src/task_pool.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 5562a5abc0a47..b538705b6742b 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -918,4 +918,23 @@ mod tests { assert!(!thread_check_failed.load(Ordering::Acquire)); assert_eq!(count.load(Ordering::Acquire), 200); } + + // This test will often freeze on other executors. + #[test] + fn test_nested_scopes() { + let pool = TaskPool::new(); + let count = Arc::new(AtomicI32::new(0)); + + pool.scope(|scope| { + scope.spawn(async { + pool.scope(|scope| { + scope.spawn(async { + count.fetch_add(1, Ordering::Relaxed); + }); + }); + }); + }); + + assert_eq!(count.load(Ordering::Acquire), 1); + } }