From b88cbed741c7de3371e627004ba8fde62578c176 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 1 Jun 2025 15:43:14 +0200 Subject: [PATCH 1/2] Make sure to sync on file-io.rs tokio test Tokio `AsyncWriteExt::write` doesn't actually ensure that the contents have written, it just *starts* the write operation. To ensure that the file has actually been written, we need to `sync_all` first. --- src/tools/miri/tests/pass-dep/tokio/file-io.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/miri/tests/pass-dep/tokio/file-io.rs b/src/tools/miri/tests/pass-dep/tokio/file-io.rs index e4e923499703..7d05260c9551 100644 --- a/src/tools/miri/tests/pass-dep/tokio/file-io.rs +++ b/src/tools/miri/tests/pass-dep/tokio/file-io.rs @@ -21,6 +21,7 @@ async fn test_create_and_write() -> io::Result<()> { // Write 10 bytes to the file. file.write_all(b"some bytes").await?; + file.sync_all().await?; // tokio doesn't necessarily complete writes until you sync. assert_eq!(file.metadata().await.unwrap().len(), 10); remove_file(&path).unwrap(); From 0884c683ad3fef0b8c02ed7fdf7aa3ee874a7e3d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 1 Jun 2025 16:27:27 +0200 Subject: [PATCH 2/2] tweak comment and use a weaker fence --- src/tools/miri/tests/pass-dep/tokio/file-io.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/tests/pass-dep/tokio/file-io.rs b/src/tools/miri/tests/pass-dep/tokio/file-io.rs index 7d05260c9551..067753203bbd 100644 --- a/src/tools/miri/tests/pass-dep/tokio/file-io.rs +++ b/src/tools/miri/tests/pass-dep/tokio/file-io.rs @@ -21,7 +21,10 @@ async fn test_create_and_write() -> io::Result<()> { // Write 10 bytes to the file. file.write_all(b"some bytes").await?; - file.sync_all().await?; // tokio doesn't necessarily complete writes until you sync. + // For tokio's file I/O, `await` does not have its usual semantics of waiting until the + // operation is completed, so we have to wait some more to make sure the write is completed. + file.flush().await?; + // Check that 10 bytes have been written. assert_eq!(file.metadata().await.unwrap().len(), 10); remove_file(&path).unwrap();