Skip to content

Commit 0055a0e

Browse files
committed
try to fix ci
--still broken
1 parent b4edfab commit 0055a0e

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

crates/bevy_app/src/app.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use bevy_ecs::{
88
SystemStage,
99
},
1010
system::Resource,
11-
1211
world::World,
1312
};
14-
use bevy_tasks::ComputeTaskPool;
13+
use bevy_tasks::{ComputeTaskPool, TaskPool};
1514
use bevy_utils::{tracing::debug, HashMap, HashSet};
1615
use std::fmt::Debug;
1716

@@ -154,7 +153,7 @@ impl App {
154153
pub fn update(&mut self) {
155154
#[cfg(feature = "trace")]
156155
let _bevy_frame_update_span = info_span!("frame").entered();
157-
ComputeTaskPool::get().scope(|scope| {
156+
ComputeTaskPool::init(TaskPool::default).scope(|scope| {
158157
if self.run_once {
159158
for sub_app in self.sub_apps.values_mut() {
160159
(sub_app.extract)(&mut self.world, &mut sub_app.app);

crates/bevy_tasks/src/main_thread_executor.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ static MAIN_THREAD_EXECUTOR: OnceCell<MainThreadExecutor> = OnceCell::new();
1010
/// Use to access the global main thread executor. Be aware that the main thread executor
1111
/// only makes progress when it is ticked. This normally happens in `[TaskPool::scope]`.
1212
#[derive(Debug)]
13-
pub struct MainThreadExecutor(Arc<Executor<'static>>);
13+
pub struct MainThreadExecutor(
14+
// this is only pub crate for testing purposes, do not contruct otherwise
15+
pub(crate) Arc<Executor<'static>>,
16+
);
1417

1518
impl MainThreadExecutor {
1619
/// Initializes the global `[MainThreadExecutor]` instance.
@@ -39,6 +42,17 @@ impl MainThreadExecutor {
3942
/// Use this to tick the main thread executor.
4043
/// Returns None if called on not the main thread.
4144
pub fn ticker(&self) -> Option<MainThreadTicker> {
45+
// always return ticker when testing to allow tests to run off main thread
46+
dbg!("hjj");
47+
#[cfg(test)]
48+
if true {
49+
dbg!("blah");
50+
return Some(MainThreadTicker {
51+
executor: self.0.clone(),
52+
_marker: PhantomData::default(),
53+
});
54+
}
55+
4256
if let Some(is_main) = is_main_thread() {
4357
if is_main {
4458
return Some(MainThreadTicker {
@@ -69,7 +83,7 @@ pub struct MainThreadTicker {
6983
impl MainThreadTicker {
7084
/// Tick the main thread executor.
7185
/// This needs to be called manually on the main thread if a `[TaskPool::scope]` is not active
72-
pub fn tick<'a>(&'a self) -> impl Future<Output = ()> + 'a {
86+
pub fn tick(&self) -> impl Future<Output = ()> + '_ {
7387
self.executor.tick()
7488
}
7589
}

crates/bevy_tasks/src/task_pool.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,15 @@ impl TaskPool {
245245
// transmute the lifetimes to 'env here to appease the compiler as it is unable to validate safety.
246246
let executor: &async_executor::Executor = &self.executor;
247247
let executor: &'env async_executor::Executor = unsafe { mem::transmute(executor) };
248-
let main_thread_spawner = MainThreadExecutor::init().spawner();
248+
249+
#[cfg(not(test))]
250+
let main_thread_executor = MainThreadExecutor::init();
251+
// for testing configure a new instance of main thread executor for every scope
252+
// this helps us pretend that the thread that an app or stage is constructed on is the main thread
253+
#[cfg(test)]
254+
let main_thread_executor = MainThreadExecutor(Arc::new(async_executor::Executor::new()));
255+
256+
let main_thread_spawner = main_thread_executor.spawner();
249257
let main_thread_spawner: MainThreadSpawner<'env> =
250258
unsafe { mem::transmute(main_thread_spawner) };
251259
let spawned: ConcurrentQueue<async_executor::Task<T>> = ConcurrentQueue::unbounded();
@@ -277,9 +285,10 @@ impl TaskPool {
277285
results
278286
};
279287

280-
if let Some(main_thread_ticker) = MainThreadExecutor::get().ticker() {
288+
if let Some(main_thread_ticker) = main_thread_executor.ticker() {
281289
let tick_forever = async move {
282290
loop {
291+
dbg!("tivk");
283292
main_thread_ticker.tick().await;
284293
}
285294
};
@@ -441,7 +450,7 @@ mod tests {
441450
}
442451

443452
#[test]
444-
fn test_mixed_spawn_on_scope_and_spawn() {
453+
fn test_mixed_spawn_on_main_and_spawn() {
445454
let pool = TaskPool::new();
446455

447456
let foo = Box::new(42);

0 commit comments

Comments
 (0)