Skip to content

Commit

Permalink
add test for nested scopes (bevyengine#10026)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
hymm authored and Ray Redondo committed Jan 9, 2024
1 parent 4b703c7 commit d9e3403
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit d9e3403

Please sign in to comment.