From 87e09a60f7b9d457ca306cc30b24c4d1f0ac7a17 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 6 Nov 2024 16:05:58 +0000 Subject: [PATCH] wait_until_i_am_the_last_task() - num_alive should be 0, not 1 --- crates/librqbit/src/tests/e2e.rs | 4 +++- crates/librqbit/src/tests/test_util.rs | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/librqbit/src/tests/e2e.rs b/crates/librqbit/src/tests/e2e.rs index b83b680..6c43556 100644 --- a/crates/librqbit/src/tests/e2e.rs +++ b/crates/librqbit/src/tests/e2e.rs @@ -23,6 +23,8 @@ use crate::{ #[tokio::test(flavor = "multi_thread", worker_threads = 64)] async fn test_e2e_download() { + wait_until_i_am_the_last_task().await.unwrap(); + let timeout = std::env::var("E2E_TIMEOUT") .ok() .and_then(|v| v.parse().ok()) @@ -38,7 +40,7 @@ async fn test_e2e_download() { .unwrap(); // Wait to ensure everything is dropped. - wait_until_i_am_the_last_task().await; + wait_until_i_am_the_last_task().await.unwrap(); drop_checks.check().unwrap(); } diff --git a/crates/librqbit/src/tests/test_util.rs b/crates/librqbit/src/tests/test_util.rs index 7f426b5..f454ccd 100644 --- a/crates/librqbit/src/tests/test_util.rs +++ b/crates/librqbit/src/tests/test_util.rs @@ -196,13 +196,13 @@ pub async fn wait_until( Ok(()) } -pub async fn wait_until_i_am_the_last_task() { +pub async fn wait_until_i_am_the_last_task() -> anyhow::Result<()> { let metrics = tokio::runtime::Handle::current().metrics(); wait_until( || { let num_alive = metrics.num_alive_tasks(); - if num_alive != 1 { - bail!("metrics.num_alive_tasks() = {num_alive}, expected 1") + if num_alive != 0 { + bail!("metrics.num_alive_tasks() = {num_alive}, expected 0") } Ok(()) }, @@ -210,5 +210,4 @@ pub async fn wait_until_i_am_the_last_task() { Duration::from_secs(6), ) .await - .unwrap(); }