pathfinder_common/
integration_testing.rs

1use std::path::Path;
2
3/// ## Important
4/// This function does nothing in production builds.
5///
6/// ## Integration testing
7/// Creates a marker file in the data directory indicating that a specific port
8/// has been assigned. This function is only active in debug builds. The file is
9/// named `{pid}_{name}_port_{value}`.
10///
11/// ## Panics
12/// The function will panic if it fails to create the marker file.
13pub fn debug_create_port_marker_file(_name: &str, _value: u16, _data_directory: &Path) {
14    #[cfg(debug_assertions)]
15    {
16        if std::env::var_os("PATHFINDER_TEST_ENABLE_PORT_MARKER_FILES").is_some() {
17            let marker_file =
18                _data_directory.join(format!("pid_{}_{}_port", std::process::id(), _name));
19            std::fs::write(&marker_file, _value.to_string()).unwrap_or_else(|_| {
20                panic!("Failed to create marker file {}", marker_file.display())
21            });
22        }
23    }
24}