Skip to content

Commit

Permalink
wait_until_i_am_the_last_task() - num_alive should be 0, not 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Nov 6, 2024
1 parent 78363d6 commit 87e09a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion crates/librqbit/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
}
Expand Down
7 changes: 3 additions & 4 deletions crates/librqbit/src/tests/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,18 @@ 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(())
},
// This needs to be higher than the timeout the tasks print "still running"
Duration::from_secs(6),
)
.await
.unwrap();
}

0 comments on commit 87e09a6

Please sign in to comment.