From 4beab41fa201dc378b7a59e94c81ba3ecb8dc9b3 Mon Sep 17 00:00:00 2001 From: kkould <2435992353@qq.com> Date: Tue, 12 Nov 2024 10:53:48 +0000 Subject: [PATCH] test: add fs test for monoio & tokio uring --- fusio/src/lib.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/fusio/src/lib.rs b/fusio/src/lib.rs index 2df3974..31b2dbf 100644 --- a/fusio/src/lib.rs +++ b/fusio/src/lib.rs @@ -372,10 +372,17 @@ mod tests { ) .await?; file.write_all("Hello! world".as_bytes()).await.0?; - + file.flush().await.unwrap(); file.close().await.unwrap(); - let (result, buf) = file.read_exact_at(vec![0u8; 12], 12).await; + let mut file = fs + .open_options( + &Path::from_absolute_path(&work_file_path)?, + OpenOptions::default().read(true), + ) + .await?; + + let (result, buf) = file.read_exact_at(vec![0u8; 12], 0).await; result.unwrap(); assert_eq!(buf.as_slice(), b"Hello! world"); } @@ -447,9 +454,17 @@ mod tests { ) .await?; src_file.write_all("Hello! world".as_bytes()).await.0?; + src_file.flush().await?; src_file.close().await?; - let (result, buf) = src_file.read_exact_at(vec![0u8; 12], 12).await; + let mut src_file = src_fs + .open_options( + &Path::from_absolute_path(&src_file_path)?, + OpenOptions::default().write(true).read(true), + ) + .await?; + + let (result, buf) = src_file.read_exact_at(vec![0u8; 12], 0).await; result.unwrap(); assert_eq!(buf.as_slice(), b"Hello! world"); @@ -494,9 +509,16 @@ mod tests { ) .await?; src_file.write_all("Hello! world".as_bytes()).await.0?; + src_file.flush().await?; src_file.close().await?; - let (result, buf) = src_file.read_exact_at(vec![0u8; 12], 12).await; + let mut src_file = src_fs + .open_options( + &Path::from_absolute_path(&src_file_path)?, + OpenOptions::default().write(true).read(true), + ) + .await?; + let (result, buf) = src_file.read_exact_at(vec![0u8; 12], 0).await; result.unwrap(); assert_eq!(buf.as_slice(), b"Hello! world"); @@ -507,9 +529,9 @@ mod tests { ) .await?; - let (result, buf) = dst_file.read_exact_at(vec![0u8; 24], 0).await; + let (result, buf) = dst_file.read_exact_at(vec![0u8; 12], 0).await; result.unwrap(); - assert_eq!(buf.as_slice(), b"Hello! fusioHello! world"); + assert_eq!(buf.as_slice(), b"Hello! world"); } Ok(())