Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hyperactor_mesh/src/actor_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,9 @@ mod tests {
use crate::alloc::process::ProcessAllocator;

fn process_allocator() -> ProcessAllocator {
ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
))
ProcessAllocator::new(Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
)))
}

#[cfg(fbcode_build)] // we use an external binary, produced by buck
Expand Down
5 changes: 3 additions & 2 deletions hyperactor_mesh/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,9 @@ pub(crate) mod testing {
Duration::from_secs(1),
);

let command =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let command = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let mut allocator = ProcessAllocator::new(command);
let mut alloc = allocator
.allocate(AllocSpec {
Expand Down
4 changes: 2 additions & 2 deletions hyperactor_mesh/src/alloc/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,12 @@ mod tests {

#[cfg(fbcode_build)] // we use an external binary, produced by buck
crate::alloc_test_suite!(ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap()
crate::testresource::get("monarch/hyperactor_mesh/bootstrap")
)));

#[tokio::test]
async fn test_sigterm_on_group_fail() {
let bootstrap_binary = buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap();
let bootstrap_binary = crate::testresource::get("monarch/hyperactor_mesh/bootstrap");
let mut allocator = ProcessAllocator::new(Command::new(bootstrap_binary));

let mut alloc = allocator
Expand Down
38 changes: 21 additions & 17 deletions hyperactor_mesh/src/alloc/remoteprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,13 +2042,15 @@ mod test_alloc {
let task1_allocator = RemoteProcessAllocator::new();
let task1_addr = ChannelAddr::any(ChannelTransport::Unix);
let task1_addr_string = task1_addr.to_string();
let task1_cmd =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let task1_cmd = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let task2_allocator = RemoteProcessAllocator::new();
let task2_addr = ChannelAddr::any(ChannelTransport::Unix);
let task2_addr_string = task2_addr.to_string();
let task2_cmd =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let task2_cmd = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let task1_allocator_copy = task1_allocator.clone();
let task1_allocator_handle = tokio::spawn(async move {
tracing::info!("spawning task1");
Expand Down Expand Up @@ -2169,13 +2171,15 @@ mod test_alloc {
let task1_allocator = RemoteProcessAllocator::new();
let task1_addr = ChannelAddr::any(ChannelTransport::Unix);
let task1_addr_string = task1_addr.to_string();
let task1_cmd =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let task1_cmd = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let task2_allocator = RemoteProcessAllocator::new();
let task2_addr = ChannelAddr::any(ChannelTransport::Unix);
let task2_addr_string = task2_addr.to_string();
let task2_cmd =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let task2_cmd = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let task1_allocator_copy = task1_allocator.clone();
let task1_allocator_handle = tokio::spawn(async move {
tracing::info!("spawning task1");
Expand Down Expand Up @@ -2297,8 +2301,9 @@ mod test_alloc {
let task1_allocator = RemoteProcessAllocator::new();
let task1_addr = ChannelAddr::any(ChannelTransport::Unix);
let task1_addr_string = task1_addr.to_string();
let task1_cmd =
Command::new(buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap());
let task1_cmd = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
));
let task2_allocator = RemoteProcessAllocator::new();
let task2_addr = ChannelAddr::any(ChannelTransport::Unix);
let task2_addr_string = task2_addr.to_string();
Expand Down Expand Up @@ -2421,10 +2426,9 @@ mod test_alloc {
let remote_process_allocators = addresses
.iter()
.map(|addr| {
Command::new(
buck_resources::get("monarch/hyperactor_mesh/remote_process_allocator")
.unwrap(),
)
Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/remote_process_allocator",
))
.env("RUST_LOG", "info")
.arg(format!("--addr={addr}"))
.stdout(std::process::Stdio::piped())
Expand All @@ -2436,9 +2440,9 @@ mod test_alloc {
let done_allocating_addr = ChannelAddr::any(ChannelTransport::Unix);
let (done_allocating_addr, mut done_allocating_rx) =
channel::serve::<()>(done_allocating_addr).unwrap();
let mut remote_process_alloc = Command::new(
buck_resources::get("monarch/hyperactor_mesh/remote_process_alloc").unwrap(),
)
let mut remote_process_alloc = Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/remote_process_alloc",
))
.arg(format!("--done-allocating-addr={}", done_allocating_addr))
.arg(format!("--addresses={}", addresses.join(",")))
.arg(format!("--num-proc-meshes={}", num_proc_meshes))
Expand Down
23 changes: 13 additions & 10 deletions hyperactor_mesh/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,14 @@ impl Bootstrap {

/// Install "kill me if parent dies" and close the race window.
pub fn install_pdeathsig_kill() -> io::Result<()> {
// SAFETY: Calling into libc; does not dereference memory, just
// asks the kernel to deliver SIGKILL on parent death.
let rc = unsafe { libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL as c_int) };
if rc != 0 {
return Err(io::Error::last_os_error());
#[cfg(target_os = "linux")]
{
// SAFETY: Calling into libc; does not dereference memory, just
// asks the kernel to deliver SIGKILL on parent death.
let rc = unsafe { libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL as c_int) };
if rc != 0 {
return Err(io::Error::last_os_error());
}
}
// Race-close: if the parent died between our exec and prctl(),
// we won't get a signal, so detect that and exit now.
Expand Down Expand Up @@ -1348,7 +1351,7 @@ impl BootstrapCommand {
#[cfg(test)]
pub(crate) fn test() -> Self {
Self {
program: buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
program: crate::testresource::get("monarch/hyperactor_mesh/bootstrap"),
arg0: None,
args: vec![],
env: HashMap::new(),
Expand Down Expand Up @@ -2553,7 +2556,7 @@ mod tests {
let manager = BootstrapProcManager::new(command);

// Spawn a fast-exiting child.
let mut cmd = Command::new("/bin/true");
let mut cmd = Command::new("true");
cmd.stdout(Stdio::null()).stderr(Stdio::null());
let child = cmd.spawn().expect("spawn true");

Expand Down Expand Up @@ -3230,9 +3233,9 @@ mod tests {
let (instance, _handle) = proc.instance("client").unwrap();

// Configure a ProcessAllocator with the bootstrap binary.
let mut allocator = ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
));
let mut allocator = ProcessAllocator::new(Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
)));
// Request a new allocation of procs from the ProcessAllocator.
let alloc = allocator
.allocate(AllocSpec {
Expand Down
1 change: 1 addition & 0 deletions hyperactor_mesh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod router;
pub mod shared_cell;
pub mod shortuuid;
pub mod test_utils;
mod testresource;
pub mod v1;

pub use actor_mesh::RootActorMesh;
Expand Down
49 changes: 49 additions & 0 deletions hyperactor_mesh/src/testresource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#![cfg(test)]

use std::path::PathBuf;

/// Fetch the named (BUCK) named resource, heuristically falling back on
/// the cargo-built path when possible. Beware! This is not actually a
/// true cargo dependency, so the binaries have to be built independently.
///
/// We should convert these tests to integration tests, so that cargo can
/// also manage the binaries.
pub fn get<S>(name: S) -> PathBuf
where
S: AsRef<str>,
{
let name = name.as_ref().to_owned();
// TODO: actually check if we're running in Buck context or not.
if let Ok(path) = buck_resources::get(name.clone()) {
return path;
}

assert!(
name.starts_with("monarch/hyperactor_mesh/"),
"invalid resource {}: must start with \"monarch/hyperactor_mesh/\"",
name
);

let path: PathBuf = name
.replace(
"monarch/hyperactor_mesh/",
"../target/debug/hyperactor_mesh_test_",
)
.into();

assert!(
path.exists(),
"no cargo-built resource at {}",
path.display()
);

path
}
2 changes: 1 addition & 1 deletion hyperactor_mesh/src/v1/host_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ mod tests {
let config = hyperactor::config::global::lock();
let _guard = config.override_key(crate::bootstrap::MESH_BOOTSTRAP_ENABLE_PDEATHSIG, false);

let program = buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap();
let program = crate::testresource::get("monarch/hyperactor_mesh/bootstrap");

let hosts = vec![free_localhost_addr(), free_localhost_addr()];

Expand Down
18 changes: 9 additions & 9 deletions hyperactor_mesh/src/v1/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub async fn proc_meshes(cx: &impl context::Actor, extent: Extent) -> Vec<ProcMe
});

meshes.push({
let mut allocator = ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
));
let mut allocator = ProcessAllocator::new(Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
)));
let alloc = allocator
.allocate(AllocSpec {
extent,
Expand Down Expand Up @@ -98,9 +98,9 @@ pub async fn allocs(extent: Extent) -> Vec<Box<dyn Alloc + Send + Sync>> {
vec![
// Box::new(LocalAllocator.allocate(spec.clone()).await.unwrap()),
Box::new(
ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
))
ProcessAllocator::new(Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
)))
.allocate(spec.clone())
.await
.unwrap(),
Expand Down Expand Up @@ -135,9 +135,9 @@ pub async fn local_proc_mesh(extent: Extent) -> (ProcMesh, Instance<()>, DialMai

/// Create a host mesh using multiple processes running on the test machine.
pub async fn host_mesh(extent: Extent) -> HostMesh {
let mut allocator = ProcessAllocator::new(Command::new(
buck_resources::get("monarch/hyperactor_mesh/bootstrap").unwrap(),
));
let mut allocator = ProcessAllocator::new(Command::new(crate::testresource::get(
"monarch/hyperactor_mesh/bootstrap",
)));
let alloc = allocator
.allocate(AllocSpec {
extent,
Expand Down