Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(fs): Add a test case for read with timeout #280

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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