Skip to content

Commit

Permalink
add workspace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tdyas committed May 10, 2024
1 parent 3c6c7ae commit 8a44531
Show file tree
Hide file tree
Showing 3 changed files with 775 additions and 44 deletions.
2 changes: 2 additions & 0 deletions src/rust/engine/process_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub mod named_caches;
pub mod named_caches_tests;

pub mod workspace;
#[cfg(test)]
pub mod workspace_tests;

pub(crate) mod fork_exec;

Expand Down
100 changes: 56 additions & 44 deletions src/rust/engine/process_execution/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use task_executor::Executor;
use tokio::process::Command;
use tokio::sync::RwLock;
use tokio_util::codec::{BytesCodec, FramedRead};
use workunit_store::RunningWorkunit;
use workunit_store::{in_workunit, RunningWorkunit};

use crate::fork_exec::spawn_process;
use crate::{
Expand Down Expand Up @@ -72,50 +72,62 @@ impl super::CommandRunner for CommandRunner {
) -> Result<FallibleProcessResultWithPlatform, ProcessError> {
let req_debug_repr = format!("{req:#?}");

let tempdir = create_sandbox(
self.executor.clone(),
&self.work_dir_base,
"workspace process",
KeepSandboxes::Never, // workspace execution cannot be replicated using local::CommandRunner script
)?;

log::debug!("tempdir = {}", tempdir.path().display());

let exclusive_spawn = prepare_workdir(
tempdir.path().to_owned(),
&self.work_dir_base,
&req,
req.input_digests.inputs.clone(),
&self.store,
&self.named_caches,
&self.immutable_inputs,
None,
None,
)
.await?;

apply_chroot(tempdir.path().to_str().unwrap(), &mut req);

self.run_and_capture_workdir(
req.clone(),
context,
self.store.clone(),
self.executor.clone(),
tempdir.path().to_owned(),
self.build_root.clone(),
exclusive_spawn,
in_workunit!(
"run_local_process_in_workspace",
req.level,
// NB: See engine::nodes::NodeKey::workunit_level for more information on why this workunit
// renders at the Process's level.
desc = Some(req.description.clone()),
|_workunit| async move {
let tempdir = create_sandbox(
self.executor.clone(),
&self.work_dir_base,
"workspace process",
KeepSandboxes::Never, // workspace execution cannot be replicated using local::CommandRunner script
)?;

log::debug!("tempdir = {}", tempdir.path().display());

let exclusive_spawn = prepare_workdir(
tempdir.path().to_owned(),
&self.work_dir_base,
&req,
req.input_digests.inputs.clone(),
&self.store,
&self.named_caches,
&self.immutable_inputs,
None,
None,
)
.await?;

apply_chroot(tempdir.path().to_str().unwrap(), &mut req);

self.run_and_capture_workdir(
req.clone(),
context,
self.store.clone(),
self.executor.clone(),
tempdir.path().to_owned(),
self.build_root.clone(),
exclusive_spawn,
)
.map_err(|msg| {
// Processes that experience no infrastructure issues should result in an "Ok" return,
// potentially with an exit code that indicates that they failed (with more information
// on stderr). Actually failing at this level indicates a failure to start or otherwise
// interact with the process, which would generally be an infrastructure or implementation
// error (something missing from the sandbox, incorrect permissions, etc).
//
// Given that this is expected to be rare, we dump the entire process definition in the
// error.
ProcessError::Unclassified(format!(
"Failed to execute: {req_debug_repr}\n\n{msg}"
))
})
.await
},
)
.map_err(|msg| {
// Processes that experience no infrastructure issues should result in an "Ok" return,
// potentially with an exit code that indicates that they failed (with more information
// on stderr). Actually failing at this level indicates a failure to start or otherwise
// interact with the process, which would generally be an infrastructure or implementation
// error (something missing from the sandbox, incorrect permissions, etc).
//
// Given that this is expected to be rare, we dump the entire process definition in the
// error.
ProcessError::Unclassified(format!("Failed to execute: {req_debug_repr}\n\n{msg}"))
})
.await
}

Expand Down
Loading

0 comments on commit 8a44531

Please sign in to comment.