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::channel::ChannelAddr;
15use crate::channel::ChannelTransport;
16use crate::reference;
17
18/// Create a test `ProcId` with a local channel address and name `"test_{name}"`.
19pub fn test_proc_id(name: &str) -> reference::ProcId {
20    reference::ProcId::with_name(
21        ChannelAddr::any(ChannelTransport::Local),
22        format!("test_{name}"),
23    )
24}
25
26/// Create a test `ProcId` with a custom address and name `"test_{name}"`.
27pub fn test_proc_id_with_addr(addr: ChannelAddr, name: &str) -> reference::ProcId {
28    reference::ProcId::with_name(addr, format!("test_{name}"))
29}
30
31/// Create a test `ActorId` with pid 0.
32pub fn test_actor_id(proc_name: &str, actor_name: &str) -> reference::ActorId {
33    test_proc_id(proc_name).actor_id(actor_name, 0)
34}
35
36/// Create a test `ActorId` with a custom pid.
37pub fn test_actor_id_with_pid(proc_name: &str, actor_name: &str, pid: usize) -> reference::ActorId {
38    test_proc_id(proc_name).actor_id(actor_name, pid)
39}
40
41/// Create a test `PortId` with pid 0.
42pub fn test_port_id(proc_name: &str, actor_name: &str, port: u64) -> reference::PortId {
43    reference::PortId::new(test_actor_id(proc_name, actor_name), port)
44}
45
46/// Create a test `PortId` with a custom pid.
47pub fn test_port_id_with_pid(
48    proc_name: &str,
49    actor_name: &str,
50    pid: usize,
51    port: u64,
52) -> reference::PortId {
53    reference::PortId::new(test_actor_id_with_pid(proc_name, actor_name, pid), port)
54}