From 9972b590ad78942d2a7715611a127e8f34d83bd1 Mon Sep 17 00:00:00 2001 From: William Manley Date: Sun, 21 Mar 2021 23:00:36 +0000 Subject: [PATCH] tests/fs_file.rs: Explicitly drop temp file from cache ...in an attempt to stimulate both the `preadv2` direct from cache codepath in addition to the punt to a threadpool uncached one. --- tokio/tests/fs_file.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs index bf2f1d7b5d3..b97fb5f6d59 100644 --- a/tokio/tests/fs_file.rs +++ b/tokio/tests/fs_file.rs @@ -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]