Skip to content

Commit

Permalink
tests/fs_file.rs: Explicitly drop temp file from cache
Browse files Browse the repository at this point in the history
...in an attempt to stimulate both the `preadv2` direct from cache
codepath in addition to the punt to a threadpool uncached one.
  • Loading branch information
wmanley committed Mar 21, 2021
1 parent 755a704 commit 9972b59
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tokio/tests/fs_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ async fn basic_read() {

assert_eq!(n, HELLO.len());
assert_eq!(&buf[..n], HELLO);

// Drop the data from cache to stimulate uncached codepath on Linux (see preadv2 in file.rs)
#[cfg(unix)]
{
use std::os::unix::io::AsRawFd;
nix::unistd::fsync(tempfile.as_raw_fd()).unwrap();
nix::fcntl::posix_fadvise(
tempfile.as_raw_fd(),
0,
0,
nix::fcntl::PosixFadviseAdvice::POSIX_FADV_DONTNEED,
)
.unwrap();
}

let n = file.read(&mut buf).await.unwrap();

assert_eq!(n, HELLO.len());
assert_eq!(&buf[..n], HELLO);
}

#[tokio::test]
Expand Down

0 comments on commit 9972b59

Please sign in to comment.