Skip to content

Commit

Permalink
metrics: make num_idle_blocking_threads test less flaky (#5302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Dec 17, 2022
1 parent e14ca72 commit 6b3727d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tokio/tests/rt_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ fn num_idle_blocking_threads() {
rt.block_on(async {
time::sleep(Duration::from_millis(5)).await;
});

// We need to wait until the blocking thread has become idle. Usually 5ms is
// enough for this to happen, but not always. When it isn't enough, sleep
// for another second. We don't always wait for a whole second since we want
// the test suite to finish quickly.
//
// Note that the timeout for idle threads to be killed is 10 seconds.
if 0 == rt.metrics().num_idle_blocking_threads() {
rt.block_on(async {
time::sleep(Duration::from_secs(1)).await;
});
}

assert_eq!(1, rt.metrics().num_idle_blocking_threads());
}

Expand Down

0 comments on commit 6b3727d

Please sign in to comment.