Merge branch 'main' into window_context_2
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user