mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-08 22:28:15 -05:00
fix(harness): add harness debug feature (#1012)
This commit is contained in:
@@ -3,7 +3,19 @@
|
|||||||
# Ensure the script runs in the folder that contains this script
|
# Ensure the script runs in the folder that contains this script
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
cargo build --release --package tlsn-harness-runner --package tlsn-harness-executor --package tlsn-server-fixture --package tlsn-harness-plot
|
RUNNER_FEATURES=""
|
||||||
|
EXECUTOR_FEATURES=""
|
||||||
|
|
||||||
|
if [ "$1" = "debug" ]; then
|
||||||
|
RUNNER_FEATURES="--features debug"
|
||||||
|
EXECUTOR_FEATURES="--no-default-features --features debug"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cargo build --release \
|
||||||
|
--package tlsn-harness-runner $RUNNER_FEATURES \
|
||||||
|
--package tlsn-harness-executor $EXECUTOR_FEATURES \
|
||||||
|
--package tlsn-server-fixture \
|
||||||
|
--package tlsn-harness-plot
|
||||||
|
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# Disable tracing events as a workaround for issue 959.
|
||||||
|
default = ["tracing/release_max_level_off"]
|
||||||
|
# Used to debug the executor itself.
|
||||||
|
debug = []
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "harness_executor"
|
name = "harness_executor"
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
@@ -28,8 +34,7 @@ tokio = { workspace = true, features = ["full"] }
|
|||||||
tokio-util = { workspace = true, features = ["compat"] }
|
tokio-util = { workspace = true, features = ["compat"] }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
# Disable tracing events as a workaround for issue 959.
|
tracing = { workspace = true }
|
||||||
tracing = { workspace = true, features = ["release_max_level_off"] }
|
|
||||||
wasm-bindgen = { workspace = true }
|
wasm-bindgen = { workspace = true }
|
||||||
tlsn-wasm = { workspace = true }
|
tlsn-wasm = { workspace = true }
|
||||||
js-sys = { workspace = true }
|
js-sys = { workspace = true }
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ publish = false
|
|||||||
[lib]
|
[lib]
|
||||||
name = "harness_runner"
|
name = "harness_runner"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# Used to debug the runner itself.
|
||||||
|
debug = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tlsn-harness-core = { workspace = true }
|
tlsn-harness-core = { workspace = true }
|
||||||
tlsn-server-fixture = { workspace = true }
|
tlsn-server-fixture = { workspace = true }
|
||||||
|
|||||||
17
crates/harness/runner/src/debug_prelude.rs
Normal file
17
crates/harness/runner/src/debug_prelude.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#![allow(unused_imports)]
|
||||||
|
pub use futures::FutureExt;
|
||||||
|
|
||||||
|
pub use tracing::{debug, error};
|
||||||
|
|
||||||
|
pub use chromiumoxide::{
|
||||||
|
Browser, Page,
|
||||||
|
cdp::{
|
||||||
|
browser_protocol::{
|
||||||
|
log::{EventEntryAdded, LogEntryLevel},
|
||||||
|
network::{EnableParams, SetCacheDisabledParams},
|
||||||
|
page::ReloadParams,
|
||||||
|
},
|
||||||
|
js_protocol::runtime::EventExceptionThrown,
|
||||||
|
},
|
||||||
|
handler::HandlerConfig,
|
||||||
|
};
|
||||||
@@ -21,6 +21,9 @@ use harness_core::{
|
|||||||
|
|
||||||
use crate::{Target, network::Namespace, rpc::Rpc};
|
use crate::{Target, network::Namespace, rpc::Rpc};
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
use crate::debug_prelude::*;
|
||||||
|
|
||||||
pub struct Executor {
|
pub struct Executor {
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
config: ExecutorConfig,
|
config: ExecutorConfig,
|
||||||
@@ -66,20 +69,34 @@ impl Executor {
|
|||||||
Id::One => self.config.network().rpc_1,
|
Id::One => self.config.network().rpc_1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let process = duct::cmd!(
|
let mut args = vec![
|
||||||
"sudo",
|
"ip".into(),
|
||||||
"ip",
|
"netns".into(),
|
||||||
"netns",
|
"exec".into(),
|
||||||
"exec",
|
self.ns.name().into(),
|
||||||
self.ns.name(),
|
"env".into(),
|
||||||
"env",
|
|
||||||
format!("CONFIG={}", serde_json::to_string(&self.config)?),
|
format!("CONFIG={}", serde_json::to_string(&self.config)?),
|
||||||
executor_path
|
];
|
||||||
)
|
|
||||||
.stdout_capture()
|
if cfg!(feature = "debug") {
|
||||||
.stderr_capture()
|
let level = &std::env::var("RUST_LOG").unwrap_or("debug".to_string());
|
||||||
.unchecked()
|
args.push("env".into());
|
||||||
.start()?;
|
args.push(format!("RUST_LOG={}", level));
|
||||||
|
};
|
||||||
|
|
||||||
|
args.push(executor_path.to_str().expect("valid path").into());
|
||||||
|
|
||||||
|
let process = duct::cmd("sudo", args);
|
||||||
|
|
||||||
|
let process = if !cfg!(feature = "debug") {
|
||||||
|
process
|
||||||
|
.stdout_capture()
|
||||||
|
.stderr_capture()
|
||||||
|
.unchecked()
|
||||||
|
.start()?
|
||||||
|
} else {
|
||||||
|
process.unchecked().start()?
|
||||||
|
};
|
||||||
|
|
||||||
let rpc = Rpc::new_native(rpc_addr).await?;
|
let rpc = Rpc::new_native(rpc_addr).await?;
|
||||||
|
|
||||||
@@ -119,10 +136,13 @@ impl Executor {
|
|||||||
"--no-sandbox",
|
"--no-sandbox",
|
||||||
format!("--user-data-dir={tmp}"),
|
format!("--user-data-dir={tmp}"),
|
||||||
format!("--allowed-ips=10.250.0.1"),
|
format!("--allowed-ips=10.250.0.1"),
|
||||||
)
|
);
|
||||||
.stderr_capture()
|
|
||||||
.stdout_capture()
|
let process = if !cfg!(feature = "debug") {
|
||||||
.start()?;
|
process.stderr_capture().stdout_capture().start()?
|
||||||
|
} else {
|
||||||
|
process.start()?
|
||||||
|
};
|
||||||
|
|
||||||
const TIMEOUT: usize = 10000;
|
const TIMEOUT: usize = 10000;
|
||||||
const DELAY: usize = 100;
|
const DELAY: usize = 100;
|
||||||
@@ -171,6 +191,38 @@ impl Executor {
|
|||||||
.new_page(&format!("http://{wasm_addr}:{wasm_port}/index.html"))
|
.new_page(&format!("http://{wasm_addr}:{wasm_port}/index.html"))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
tokio::spawn(register_listeners(page.clone()).await?);
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
async fn register_listeners(page: Page) -> Result<impl Future<Output = ()>> {
|
||||||
|
let mut logs = page.event_listener::<EventEntryAdded>().await?.fuse();
|
||||||
|
let mut exceptions =
|
||||||
|
page.event_listener::<EventExceptionThrown>().await?.fuse();
|
||||||
|
|
||||||
|
Ok(futures::future::join(
|
||||||
|
async move {
|
||||||
|
while let Some(event) = logs.next().await {
|
||||||
|
let entry = &event.entry;
|
||||||
|
match entry.level {
|
||||||
|
LogEntryLevel::Error => {
|
||||||
|
error!("{:?}", entry);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
debug!("{:?}: {}", entry.timestamp, entry.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async move {
|
||||||
|
while let Some(event) = exceptions.next().await {
|
||||||
|
error!("{:?}", event);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.map(|_| ()))
|
||||||
|
}
|
||||||
|
|
||||||
page.execute(EnableParams::builder().build()).await?;
|
page.execute(EnableParams::builder().build()).await?;
|
||||||
page.execute(SetCacheDisabledParams {
|
page.execute(SetCacheDisabledParams {
|
||||||
cache_disabled: true,
|
cache_disabled: true,
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ mod server_fixture;
|
|||||||
pub mod wasm_server;
|
pub mod wasm_server;
|
||||||
mod ws_proxy;
|
mod ws_proxy;
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
mod debug_prelude;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -24,6 +27,9 @@ use cli::{Cli, Command};
|
|||||||
use executor::Executor;
|
use executor::Executor;
|
||||||
use server_fixture::ServerFixture;
|
use server_fixture::ServerFixture;
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
use crate::debug_prelude::*;
|
||||||
|
|
||||||
use crate::{cli::Route, network::Network, wasm_server::WasmServer, ws_proxy::WsProxy};
|
use crate::{cli::Route, network::Network, wasm_server::WasmServer, ws_proxy::WsProxy};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
|
||||||
@@ -113,6 +119,9 @@ impl Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn main() -> Result<()> {
|
pub async fn main() -> Result<()> {
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let mut runner = Runner::new(&cli)?;
|
let mut runner = Runner::new(&cli)?;
|
||||||
|
|
||||||
@@ -227,6 +236,9 @@ pub async fn main() -> Result<()> {
|
|||||||
// Wait for the network to stabilize
|
// Wait for the network to stabilize
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
debug!("Starting bench in group {:?}", config.group);
|
||||||
|
|
||||||
let (output, _) = tokio::try_join!(
|
let (output, _) = tokio::try_join!(
|
||||||
runner.exec_p.bench(BenchCmd {
|
runner.exec_p.bench(BenchCmd {
|
||||||
config: config.clone(),
|
config: config.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user