Skip to content

Commit

Permalink
test(fs): Add a test case for read with timeout (#280)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Jul 21, 2024
1 parent 56024ab commit cf93207
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion compio-fs/tests/file.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit cf93207

Please sign in to comment.