Skip to content

Commit cf93207

Browse files
authored
test(fs): Add a test case for read with timeout (#280)
Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 56024ab commit cf93207

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compio-fs/tests/file.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::io::prelude::*;
1+
use std::{io::prelude::*, time::Duration};
22

33
use compio_fs::File;
44
use compio_io::{AsyncReadAtExt, AsyncWriteAt, AsyncWriteAtExt};
5+
use compio_runtime::time::timeout;
56
use tempfile::NamedTempFile;
67

78
#[compio_macros::test]
@@ -79,6 +80,21 @@ async fn cancel_read() {
7980
read_hello(&file).await;
8081
}
8182

83+
#[compio_macros::test]
84+
async fn timeout_read() {
85+
let mut tempfile = tempfile();
86+
tempfile.write_all(HELLO).unwrap();
87+
88+
let file = File::open(tempfile.path()).await.unwrap();
89+
90+
// Read a file with timeout.
91+
let _ = timeout(Duration::from_nanos(1), async { read_hello(&file).await })
92+
.await
93+
.unwrap_err();
94+
95+
read_hello(&file).await;
96+
}
97+
8298
#[compio_macros::test]
8399
async fn drop_open() {
84100
let tempfile = tempfile();

0 commit comments

Comments
 (0)