Drop check better message
This commit is contained in:
parent
2ad5fa2f12
commit
a5abe97735
2 changed files with 18 additions and 6 deletions
|
|
@ -38,7 +38,12 @@ async fn test_e2e_download() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Wait to ensure everything is dropped.
|
// Wait to ensure everything is dropped.
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
|
let metrics = tokio::runtime::Handle::current().metrics();
|
||||||
|
assert_eq!(metrics.num_alive_tasks(), 1);
|
||||||
|
|
||||||
|
drop_checks.check().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn _test_e2e_download(drop_checks: &DropChecks) {
|
async fn _test_e2e_download(drop_checks: &DropChecks) {
|
||||||
|
|
|
||||||
|
|
@ -149,12 +149,19 @@ impl DropChecks {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for DropCheck {
|
pub fn check(&self) -> anyhow::Result<()> {
|
||||||
fn drop(&mut self) {
|
let mut still_running = Vec::new();
|
||||||
if self.obj.upgrade().is_some() {
|
for dc in self.0.read().iter() {
|
||||||
panic!("memory leak: {}", self.name);
|
if dc.obj.upgrade().is_some() {
|
||||||
|
still_running.push(dc.name.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if !still_running.is_empty() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"still existing objects that were supposed to be dropped: {still_running:#?}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue