Skip to content

Commit 202b9fc

Browse files
authored
add test for nested scopes (#10026)
# Objective - When I've tested alternative async executors with bevy a common problem is that they deadlock when we try to run nested scopes. i.e. running a multithreaded schedule from inside another multithreaded schedule. This adds a test to bevy_tasks for that so the issue can be spotted earlier while developing. ## Changelog - add a test for nested scopes.
1 parent 7541bf8 commit 202b9fc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/bevy_tasks/src/task_pool.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,4 +918,23 @@ mod tests {
918918
assert!(!thread_check_failed.load(Ordering::Acquire));
919919
assert_eq!(count.load(Ordering::Acquire), 200);
920920
}
921+
922+
// This test will often freeze on other executors.
923+
#[test]
924+
fn test_nested_scopes() {
925+
let pool = TaskPool::new();
926+
let count = Arc::new(AtomicI32::new(0));
927+
928+
pool.scope(|scope| {
929+
scope.spawn(async {
930+
pool.scope(|scope| {
931+
scope.spawn(async {
932+
count.fetch_add(1, Ordering::Relaxed);
933+
});
934+
});
935+
});
936+
});
937+
938+
assert_eq!(count.load(Ordering::Acquire), 1);
939+
}
921940
}

0 commit comments

Comments
 (0)