time: make timeout robust against budget-depleting tasks (#4314)

This commit is contained in:
Braulio Valdivielso Martínez
2021-12-15 11:59:21 +01:00
committed by GitHub
parent 4e3268d222
commit 54e6693dff
3 changed files with 43 additions and 15 deletions
+13
View File
@@ -135,3 +135,16 @@ async fn deadline_future_elapses() {
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
}
#[tokio::test]
async fn timeout_is_not_exhausted_by_future() {
let fut = timeout(ms(1), async {
let mut buffer = [0u8; 1];
loop {
use tokio::io::AsyncReadExt;
let _ = tokio::io::empty().read(&mut buffer).await;
}
});
assert!(fut.await.is_err());
}