Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Jun 30, 2024
1 parent 4ed0054 commit 8f29c2d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tokio/tests/rt_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,35 @@ fn blocking_queue_depth() {
}

#[test]
fn num_active_tasks() {
fn num_alive_tasks() {
let rt = current_thread();
let metrics = rt.metrics();
assert_eq!(0, metrics.num_active_tasks());
assert_eq!(0, metrics.num_alive_tasks());
rt.block_on(rt.spawn(async move {
assert_eq!(1, metrics.num_active_tasks());
assert_eq!(1, metrics.num_alive_tasks());
}))
.unwrap();

assert_eq!(0, rt.metrics().num_active_tasks());
assert_eq!(0, rt.metrics().num_alive_tasks());

let rt = threaded();
let metrics = rt.metrics();
assert_eq!(0, metrics.num_active_tasks());
assert_eq!(0, metrics.num_alive_tasks());
rt.block_on(rt.spawn(async move {
assert_eq!(1, metrics.num_active_tasks());
assert_eq!(1, metrics.num_alive_tasks());
}))
.unwrap();

// try for 10 seconds to see if this eventually succeeds.
// wake_join() is called before the task is released, so in multithreaded
// code, this means we sometimes exit the block_on before the counter decrements.
for _ in 0..100 {
if rt.metrics().num_active_tasks() == 0 {
if rt.metrics().num_alive_tasks() == 0 {
break;
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
assert_eq!(0, rt.metrics().num_active_tasks());
assert_eq!(0, rt.metrics().num_alive_tasks());
}

#[test]
Expand Down

0 comments on commit 8f29c2d

Please sign in to comment.