Skip to main content

hyperactor/testing/
ids.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Standardized test ID constructors.
10//!
11//! All functions prefix the name component with `test_` so that
12//! test-originated IDs are distinguishable from production ones.
13
14use crate::ActorAddr;
15use crate::PortAddr;
16use crate::ProcAddr;
17use crate::channel::ChannelAddr;
18use crate::channel::ChannelTransport;
19
20/// Create a test `ProcAddr` with a local channel address and name `"test_{name}"`.
21pub fn test_proc_id(name: &str) -> ProcAddr {
22    ProcAddr::singleton(
23        ChannelAddr::any(ChannelTransport::Local),
24        format!("test_{name}"),
25    )
26}
27
28/// Create a test `ProcAddr` with a custom address and name `"test_{name}"`.
29pub fn test_proc_id_with_addr(addr: ChannelAddr, name: &str) -> ProcAddr {
30    ProcAddr::singleton(addr, format!("test_{name}"))
31}
32
33/// Create a test `ActorAddr`.
34pub fn test_actor_id(proc_name: &str, actor_name: &str) -> ActorAddr {
35    test_proc_id(proc_name).actor_addr(actor_name)
36}
37
38/// Create a test `PortAddr`.
39pub fn test_port_id(proc_name: &str, actor_name: &str, port: u64) -> PortAddr {
40    test_actor_id(proc_name, actor_name).port_addr(port.into())
41}