mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-05-08 09:58:01 +00:00
move tests around and add (non working) benchmark
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
//! Commands that we can use when running `cargo test` style tests in this workspace
|
||||
//! that want to test the current code.
|
||||
use crate::server::Command;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Runs `cargo run` in the current workspace to start up a telemetry shard process.
|
||||
///
|
||||
/// Note: The CWD must be somewhere within this backend workspace for the command to work.
|
||||
pub fn cargo_run_telemetry_shard(release_mode: bool) -> Result<Command, std::io::Error> {
|
||||
telemetry_command("telemetry_shard", release_mode)
|
||||
}
|
||||
|
||||
/// Runs `cargo run` in the current workspace to start up a telemetry core process.
|
||||
///
|
||||
/// Note: The CWD must be somewhere within this backend workspace for the command to work.
|
||||
pub fn cargo_run_telemetry_core(release_mode: bool) -> Result<Command, std::io::Error> {
|
||||
telemetry_command("telemetry_core", release_mode)
|
||||
}
|
||||
|
||||
fn telemetry_command(bin: &'static str, release_mode: bool) -> Result<Command, std::io::Error> {
|
||||
let mut workspace_dir = try_find_workspace_dir()?;
|
||||
workspace_dir.push("Cargo.toml");
|
||||
|
||||
let mut cmd = Command::new("cargo").arg("run");
|
||||
|
||||
// Release mode?
|
||||
if release_mode {
|
||||
cmd = cmd.arg("--release");
|
||||
}
|
||||
|
||||
cmd = cmd.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--manifest-path")
|
||||
.arg(workspace_dir)
|
||||
.arg("--");
|
||||
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
/// A _very_ naive way to find the workspace ("backend") directory
|
||||
/// from the current path (which is assumed to be inside it).
|
||||
fn try_find_workspace_dir() -> Result<PathBuf, std::io::Error> {
|
||||
let mut dir = std::env::current_dir()?;
|
||||
while !dir.ends_with("backend") && dir.pop() {}
|
||||
Ok(dir)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
mod commands;
|
||||
mod start_server;
|
||||
|
||||
pub use start_server::{ start_server_debug, start_server_release };
|
||||
@@ -0,0 +1,30 @@
|
||||
use super::commands;
|
||||
use crate::server::{self, Server, Command};
|
||||
|
||||
/// Start a telemetry core server. We'll use `cargo run` by default, to ensure that
|
||||
/// the code we run is uptodate, but you can also provide env vars to configure the binary
|
||||
/// that runs for the shard and core process:
|
||||
///
|
||||
/// TELEMETRY_SHARD_BIN - path to telemetry_shard binary
|
||||
/// TELEMETRY_CORE_BIN - path to telemetry_core binary
|
||||
async fn start_server(release_mode: bool) -> Server {
|
||||
let shard_command = std::env::var("TELEMETRY_SHARD_BIN")
|
||||
.map(|val| Command::new(val))
|
||||
.unwrap_or_else(|_| commands::cargo_run_telemetry_shard(release_mode).expect("valid shard command"));
|
||||
|
||||
let core_command = std::env::var("TELEMETRY_CORE_BIN")
|
||||
.map(|val| Command::new(val))
|
||||
.unwrap_or_else(|_| commands::cargo_run_telemetry_core(release_mode).expect("valid core command"));
|
||||
|
||||
Server::start(server::StartOpts { shard_command, core_command }).await.unwrap()
|
||||
}
|
||||
|
||||
/// Start a telemetry server using debug builds for compile speed
|
||||
pub async fn start_server_debug() -> Server {
|
||||
start_server(false).await
|
||||
}
|
||||
|
||||
/// Start a telemetry server using release builds for performance accuracy
|
||||
pub async fn start_server_release() -> Server {
|
||||
start_server(true).await
|
||||
}
|
||||
Reference in New Issue
Block a user