Merge branch 'main' into window_context_2

This commit is contained in:
Antonio Scandurra
2023-04-14 12:07:09 +02:00
53 changed files with 3951 additions and 2474 deletions
+3 -3
View File
@@ -2086,7 +2086,7 @@ impl UpgradeModelHandle for AppContext {
&self,
handle: &WeakModelHandle<T>,
) -> Option<ModelHandle<T>> {
if self.models.contains_key(&handle.model_id) {
if self.ref_counts.lock().is_entity_alive(handle.model_id) {
Some(ModelHandle::new(handle.model_id, &self.ref_counts))
} else {
None
@@ -2094,11 +2094,11 @@ impl UpgradeModelHandle for AppContext {
}
fn model_handle_is_upgradable<T: Entity>(&self, handle: &WeakModelHandle<T>) -> bool {
self.models.contains_key(&handle.model_id)
self.ref_counts.lock().is_entity_alive(handle.model_id)
}
fn upgrade_any_model_handle(&self, handle: &AnyWeakModelHandle) -> Option<AnyModelHandle> {
if self.models.contains_key(&handle.model_id) {
if self.ref_counts.lock().is_entity_alive(handle.model_id) {
Some(AnyModelHandle::new(
handle.model_id,
handle.model_type,
+1
View File
@@ -31,6 +31,7 @@ use super::{
ref_counts::LeakDetector, window_input_handler::WindowInputHandler, AsyncAppContext, RefCounts,
};
#[derive(Clone)]
pub struct TestAppContext {
cx: Rc<RefCell<AppContext>>,
foreground_platform: Rc<platform::test::ForegroundPlatform>,
+10
View File
@@ -829,6 +829,16 @@ impl Background {
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn rng<'a>(&'a self) -> impl 'a + std::ops::DerefMut<Target = rand::prelude::StdRng> {
match self {
Self::Deterministic { executor, .. } => {
parking_lot::lock_api::MutexGuard::map(executor.state.lock(), |s| &mut s.rng)
}
_ => panic!("this method can only be called on a deterministic executor"),
}
}
#[cfg(any(test, feature = "test-support"))]
pub async fn simulate_random_delay(&self) {
match self {
+2
View File
@@ -46,6 +46,7 @@ pub fn run_test(
Arc<executor::Deterministic>,
u64,
)),
on_fail_fn: Option<fn()>,
fn_name: String,
) {
// let _profiler = dhat::Profiler::new_heap();
@@ -178,6 +179,7 @@ pub fn run_test(
if is_randomized {
eprintln!("failing seed: {}", atomic_seed.load(SeqCst));
}
on_fail_fn.map(|f| f());
panic::resume_unwind(error);
}
}