From bd20e266602c15c8fc7895e7cc6a534d5d107d3b 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. --- tests/pass-dep/tokio/file-io.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pass-dep/tokio/file-io.rs b/tests/pass-dep/tokio/file-io.rs index e4e9234997..7d05260c95 100644 --- a/tests/pass-dep/tokio/file-io.rs +++ b/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 bda28aa38d93b8f221eaf45a14f7d516688e950e 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 --- tests/pass-dep/tokio/file-io.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/pass-dep/tokio/file-io.rs b/tests/pass-dep/tokio/file-io.rs index 7d05260c95..067753203b 100644 --- a/tests/pass-dep/tokio/file-io.rs +++ b/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();