Skip to content

Commit

Permalink
Fix flakey tests due to sync_all() not being called
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Sep 10, 2023
1 parent a9709b4 commit 6c931fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cas/store/tests/filesystem_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ async fn write_file(file_name: &OsStr, data: &[u8]) -> Result<(), Error> {
let mut file = fs::create_file(file_name)
.await
.err_tip(|| format!("Failed to create file: {file_name:?}"))?;
Ok(file.as_writer().await?.write_all(data).await?)
file.as_writer().await?.write_all(data).await?;
file.as_writer()
.await?
.as_mut()
.sync_all()
.await
.err_tip(|| "Could not sync file")
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions cas/worker/tests/local_worker_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ mod local_worker_tests {
fs::create_dir_all(format!("{}/{}", work_directory, "another_dir")).await?;
let mut file = fs::create_file(OsString::from(format!("{}/{}", work_directory, "foo.txt"))).await?;
file.as_writer().await?.write_all(b"Hello, world!").await?;
file.as_writer().await?.as_mut().sync_all().await?;
new_local_worker(
Arc::new(LocalWorkerConfig {
work_directory: work_directory.clone(),
Expand Down Expand Up @@ -389,6 +390,7 @@ mod local_worker_tests {
let precondition_script = format!("{}/precondition.sh", temp_path);
let mut file = fs::create_file(OsString::from(&precondition_script)).await?;
file.as_writer().await?.write_all(b"#!/bin/sh\nexit 1\n").await?;
file.as_writer().await?.as_mut().sync_all().await?;
fs::set_permissions(&precondition_script, Permissions::from_mode(0o777)).await?;
precondition_script
};
Expand All @@ -397,6 +399,7 @@ mod local_worker_tests {
let precondition_script = format!("{}/precondition.bat", temp_path);
let mut file = fs::create_file(OsString::from(&precondition_script)).await?;
file.as_writer().await?.write_all(b"@echo off\r\nexit 1").await?;
file.as_writer().await?.as_mut().sync_all().await?;
precondition_script
};
let local_worker_config = LocalWorkerConfig {
Expand Down
6 changes: 6 additions & 0 deletions cas/worker/tests/running_actions_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,12 @@ exit 0
.await?
.write_all(TEST_WRAPPER_SCRIPT_CONTENT.as_bytes())
.await?;
test_wrapper_script_handle
.as_writer()
.await?
.as_mut()
.sync_all()
.await?;
#[cfg(target_family = "unix")]
fs::set_permissions(&test_wrapper_script, Permissions::from_mode(0o755)).await?;
test_wrapper_script
Expand Down

0 comments on commit 6c931fa

Please sign in to comment.