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,5 +1,6 @@
|
|||
use backtrace::{Backtrace, BacktraceFmt, BytesOrWideString};
|
||||
use smol::future::FutureExt;
|
||||
use std::{future::Future, time::Duration};
|
||||
use std::{fmt, future::Future, time::Duration};
|
||||
|
||||
pub fn post_inc(value: &mut usize) -> usize {
|
||||
let prev = *value;
|
||||
|
@ -18,3 +19,27 @@ where
|
|||
let future = async move { Ok(f.await) };
|
||||
timer.race(future).await
|
||||
}
|
||||
|
||||
pub struct CwdBacktrace<'a>(pub &'a Backtrace);
|
||||
|
||||
impl<'a> std::fmt::Debug for CwdBacktrace<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let cwd = cwd.parent().unwrap();
|
||||
let mut print_path = |fmt: &mut fmt::Formatter<'_>, path: BytesOrWideString<'_>| {
|
||||
fmt::Display::fmt(&path, fmt)
|
||||
};
|
||||
let mut fmt = BacktraceFmt::new(f, backtrace::PrintFmt::Full, &mut print_path);
|
||||
for frame in self.0.frames() {
|
||||
let mut formatted_frame = fmt.frame();
|
||||
if frame
|
||||
.symbols()
|
||||
.iter()
|
||||
.any(|s| s.filename().map_or(false, |f| f.starts_with(&cwd)))
|
||||
{
|
||||
formatted_frame.backtrace_frame(frame)?;
|
||||
}
|
||||
}
|
||||
fmt.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue