Start work on detecting leaked handles in tests
For now, just track models. Tests fail because we don't yet clear the app contexts at the right time. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
d1d324e42b
commit
7d53e37672
6 changed files with 196 additions and 89 deletions
|
@ -1,3 +1,10 @@
|
|||
use crate::{
|
||||
executor, platform, Entity, FontCache, Handle, LeakDetector, MutableAppContext, Platform,
|
||||
Subscription, TestAppContext,
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use parking_lot::Mutex;
|
||||
use smol::channel;
|
||||
use std::{
|
||||
panic::{self, RefUnwindSafe},
|
||||
rc::Rc,
|
||||
|
@ -7,14 +14,6 @@ use std::{
|
|||
},
|
||||
};
|
||||
|
||||
use futures::StreamExt;
|
||||
use smol::channel;
|
||||
|
||||
use crate::{
|
||||
executor, platform, Entity, FontCache, Handle, MutableAppContext, Platform, Subscription,
|
||||
TestAppContext,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
#[ctor::ctor]
|
||||
fn init_logger() {
|
||||
|
@ -65,24 +64,27 @@ pub fn run_test(
|
|||
}
|
||||
|
||||
let deterministic = executor::Deterministic::new(seed);
|
||||
let leak_detector = Arc::new(Mutex::new(LeakDetector::default()));
|
||||
let mut cx = TestAppContext::new(
|
||||
foreground_platform.clone(),
|
||||
platform.clone(),
|
||||
deterministic.build_foreground(usize::MAX),
|
||||
deterministic.build_background(),
|
||||
font_cache.clone(),
|
||||
leak_detector.clone(),
|
||||
0,
|
||||
);
|
||||
cx.update(|cx| {
|
||||
test_fn(
|
||||
cx,
|
||||
foreground_platform.clone(),
|
||||
deterministic,
|
||||
deterministic.clone(),
|
||||
seed,
|
||||
is_last_iteration,
|
||||
)
|
||||
});
|
||||
|
||||
leak_detector.lock().detect();
|
||||
if is_last_iteration {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue