Skip to content

Commit

Permalink
Attempt to fix flaky tests regarding Text file busy error
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Sep 12, 2023
1 parent 4c71336 commit 637c8a9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cas/store/filesystem_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ impl<Fe: FileEntry> FilesystemStore<Fe> {
file_size += data_len as u64;
}

resumeable_temp_file
.as_writer()
.await
.err_tip(|| "in filesystem_store::update_file")?
.flush()
.await
.err_tip(|| "Could not flush file in filesystem store")?;
resumeable_temp_file
.as_writer()
.await
Expand Down
1 change: 1 addition & 0 deletions cas/store/tests/ac_utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod ac_utils_tests {
file.write_all(&expected_data)
.await
.err_tip(|| "Could not write to file")?;
file.flush().await.err_tip(|| "Could not flush file")?;
file.sync_all().await.err_tip(|| "Could not sync file")?;
}
{
Expand Down
1 change: 1 addition & 0 deletions cas/store/tests/filesystem_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ async fn write_file(file_name: &OsStr, data: &[u8]) -> Result<(), Error> {
.await
.err_tip(|| format!("Failed to create file: {file_name:?}"))?;
file.as_writer().await?.write_all(data).await?;
file.as_writer().await?.flush().await?;
file.as_writer()
.await?
.as_mut()
Expand Down
12 changes: 8 additions & 4 deletions cas/worker/tests/local_worker_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +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?;
file.as_writer().await?.flush().await?;
new_local_worker(
Arc::new(LocalWorkerConfig {
work_directory: work_directory.clone(),
Expand Down Expand Up @@ -390,16 +390,20 @@ 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?;
file.as_writer()
.await?
.as_mut()
.set_permissions(Permissions::from_mode(0o777))
.await?;
file.as_writer().await?.flush().await?;
precondition_script
};
#[cfg(target_family = "windows")]
let precondition_script = {
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?;
file.as_writer().await?.flush().await?;
precondition_script
};
let local_worker_config = LocalWorkerConfig {
Expand Down
36 changes: 30 additions & 6 deletions cas/worker/tests/running_actions_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,13 @@ mod running_actions_manager_tests {
#[cfg(target_family = "unix")]
let arguments = vec!["sh".to_string(), "-c".to_string(), "sleep infinity".to_string()];
#[cfg(target_family = "windows")]
let arguments = vec!["cmd".to_string(), "/C".to_string(), "Timeout 99999".to_string()];
// Windows is weird with timeout, so we use ping. See:
// https://www.ibm.com/support/pages/timeout-command-run-batch-job-exits-immediately-and-returns-error-input-redirection-not-supported-exiting-process-immediately
let arguments = vec![
"cmd".to_string(),
"/C".to_string(),
"ping -n 99999 127.0.0.1".to_string(),
];

let command = Command {
arguments,
Expand Down Expand Up @@ -1106,14 +1112,20 @@ exit 0
.await?
.write_all(TEST_WRAPPER_SCRIPT_CONTENT.as_bytes())
.await?;
#[cfg(target_family = "unix")]
test_wrapper_script_handle
.as_writer()
.await?
.as_mut()
.set_permissions(Permissions::from_mode(0o755))
.await?;
test_wrapper_script_handle.as_writer().await?.flush().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 Expand Up @@ -1536,7 +1548,13 @@ exit 0
#[cfg(target_family = "unix")]
let arguments = vec!["sh".to_string(), "-c".to_string(), "sleep infinity".to_string()];
#[cfg(target_family = "windows")]
let arguments = vec!["cmd".to_string(), "/C".to_string(), "timeout 99999".to_string()];
// Windows is weird with timeout, so we use ping. See:
// https://www.ibm.com/support/pages/timeout-command-run-batch-job-exits-immediately-and-returns-error-input-redirection-not-supported-exiting-process-immediately
let arguments = vec![
"cmd".to_string(),
"/C".to_string(),
"ping -n 99999 127.0.0.1".to_string(),
];

let command = Command {
arguments,
Expand Down Expand Up @@ -1619,7 +1637,13 @@ exit 0
#[cfg(target_family = "unix")]
let arguments = vec!["sh".to_string(), "-c".to_string(), "sleep infinity".to_string()];
#[cfg(target_family = "windows")]
let arguments = vec!["cmd".to_string(), "/C".to_string(), "Timeout 99999".to_string()];
// Windows is weird with timeout, so we use ping. See:
// https://www.ibm.com/support/pages/timeout-command-run-batch-job-exits-immediately-and-returns-error-input-redirection-not-supported-exiting-process-immediately
let arguments = vec![
"cmd".to_string(),
"/C".to_string(),
"ping -n 99999 127.0.0.1".to_string(),
];

let command = Command {
arguments,
Expand Down Expand Up @@ -1701,7 +1725,7 @@ exit 0
let err = action_result
.error
.as_ref()
.err_tip(|| format!("{:?}", action_result))?;
.err_tip(|| format!("No error exists in result : {:?}", action_result))?;
assert_eq!(err.code, Code::Aborted, "Expected Aborted : {action_result:?}");
}

Expand Down
4 changes: 4 additions & 0 deletions util/tests/fs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod fs_tests {
assert_eq!(fs::get_open_files_for_test(), 0);
file.as_writer().await?.write_all(b"Goodbye").await?;
assert_eq!(fs::get_open_files_for_test(), 1);
file.as_writer().await?.flush().await?;
file.as_writer().await?.as_mut().sync_all().await?;
}
assert_eq!(fs::get_open_files_for_test(), 0);
Expand All @@ -74,6 +75,7 @@ mod fs_tests {
{
let mut file = fs::create_file(&filename).await?;
file.as_writer().await?.write_all(DUMMYDATA.as_bytes()).await?;
file.as_writer().await?.flush().await?;
file.as_writer().await?.as_mut().sync_all().await?;
}
{
Expand Down Expand Up @@ -105,6 +107,7 @@ mod fs_tests {
{
let mut file = fs::create_file(&filename).await?;
file.as_writer().await?.write_all(DUMMYDATA.as_bytes()).await?;
file.as_writer().await?.flush().await?;
file.as_writer().await?.as_mut().sync_all().await?;
}
{
Expand Down Expand Up @@ -140,6 +143,7 @@ mod fs_tests {
{
let mut file = fs::create_file(&filename).await?;
file.as_writer().await?.write_all(DUMMYDATA.as_bytes()).await?;
file.as_writer().await?.flush().await?;
file.as_writer().await?.as_mut().sync_all().await?;
}
{
Expand Down

0 comments on commit 637c8a9

Please sign in to comment.