diff --git a/compio-fs/tests/file.rs b/compio-fs/tests/file.rs index 5ddc13bd..7bc4629b 100644 --- a/compio-fs/tests/file.rs +++ b/compio-fs/tests/file.rs @@ -1,7 +1,8 @@ -use std::io::prelude::*; +use std::{io::prelude::*, time::Duration}; use compio_fs::File; use compio_io::{AsyncReadAtExt, AsyncWriteAt, AsyncWriteAtExt}; +use compio_runtime::time::timeout; use tempfile::NamedTempFile; #[compio_macros::test] @@ -79,6 +80,21 @@ async fn cancel_read() { read_hello(&file).await; } +#[compio_macros::test] +async fn timeout_read() { + let mut tempfile = tempfile(); + tempfile.write_all(HELLO).unwrap(); + + let file = File::open(tempfile.path()).await.unwrap(); + + // Read a file with timeout. + let _ = timeout(Duration::from_nanos(1), async { read_hello(&file).await }) + .await + .unwrap_err(); + + read_hello(&file).await; +} + #[compio_macros::test] async fn drop_open() { let tempfile = tempfile();