mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-27 09:18:00 +00:00
move tests around and add (non working) benchmark
This commit is contained in:
@@ -13,3 +13,6 @@ pub mod ws_client;
|
||||
/// in an iterable container.
|
||||
#[macro_use]
|
||||
pub mod contains_matches;
|
||||
|
||||
/// Utilities to help with running tests from within this current workspace.
|
||||
pub mod workspace;
|
||||
@@ -1,36 +0,0 @@
|
||||
//! A pair of commands we can use when running `cargo test` style tests in this workspace
|
||||
//! that want to test the current code. For more external tests, we may want to ask for the
|
||||
//! commands, or connect to a running instance instead.
|
||||
|
||||
use super::Command;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Runs `cargo run` in the current workspace to start up a telemetry shard process
|
||||
pub fn telemetry_shard() -> Result<Command, std::io::Error> {
|
||||
telemetry_command("telemetry_shard")
|
||||
}
|
||||
|
||||
/// Runs `cargo run` in the current workspace to start up a telemetry core process
|
||||
pub fn telemetry_core() -> Result<Command, std::io::Error> {
|
||||
telemetry_command("telemetry_core")
|
||||
}
|
||||
|
||||
fn telemetry_command(bin: &'static str) -> Result<Command, std::io::Error> {
|
||||
let mut workspace_dir = try_find_workspace_dir()?;
|
||||
workspace_dir.push("Cargo.toml");
|
||||
Ok(Command::new("cargo")
|
||||
.arg("run")
|
||||
.arg("--bin")
|
||||
.arg(bin)
|
||||
.arg("--manifest-path")
|
||||
.arg(workspace_dir)
|
||||
.arg("--"))
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
mod server;
|
||||
mod utils;
|
||||
|
||||
pub mod cargo_run_commands;
|
||||
pub mod channels;
|
||||
pub use server::*;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -11,10 +11,15 @@ pub struct Sender {
|
||||
}
|
||||
|
||||
impl Sender {
|
||||
/// Ask the underlying Websocket connection to close.
|
||||
pub async fn close(&mut self) -> Result<(), SendError> {
|
||||
self.inner.send(SentMessage::Close).await?;
|
||||
Ok(())
|
||||
}
|
||||
/// Returns whether this channel is closed.
|
||||
pub fn is_closed(&mut self) -> bool {
|
||||
self.inner.is_closed()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user