Skip to content

Commit

Permalink
BFT-457: Separate logging init
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jun 12, 2024
1 parent d910e9b commit 1dbe86b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 2 additions & 4 deletions node/actors/bft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ async fn twins_network_w2_twins_w_partitions() {
#[tokio::test(flavor = "multi_thread")]
#[should_panic]
async fn twins_network_to_fail() {
run_twins(5, 1, 100)
.await
.expect_err("will fail with assert");
run_twins(5, 1, 100).await.unwrap();
}

/// Create network configuration for a given number of replicas and twins and run [Test].
Expand All @@ -270,10 +268,10 @@ async fn run_twins(

// If we pass more twins than tolerable faulty replicas then it should fail with an assertion error,
// but if we abort the process on panic then the #[should_panic] attribute doesn't work with `cargo nextest`.
// Unfortunately this also turns off logging, but it's fine this is just to make sure Twins catch _something_.
if num_twins <= max_faulty {
zksync_concurrency::testonly::abort_on_panic();
}
zksync_concurrency::testonly::init_tracing();

let ctx = &ctx::test_root(&ctx::AffineClock::new(10.0));
// Use a single timeout for all scenarios to finish.
Expand Down
19 changes: 13 additions & 6 deletions node/libs/concurrency/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ use std::{future::Future, io::IsTerminal as _};
// TODO: investigate whether "-Zpanic-abort-tests" could replace this function once the flag
// becomes stable: https://github.com/rust-lang/rust/issues/67650, so we don't use it.
pub fn abort_on_panic() {
let _ = tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_test_writer()
.with_ansi(std::env::var("NO_COLOR").is_err() && std::io::stdout().is_terminal())
.with_line_number(true)
.try_init();
init_tracing();

// I don't know a way to set panic=abort for nextest builds in compilation time, so we set it
// in runtime. https://nexte.st/book/env-vars.html#environment-variables-nextest-sets
Expand All @@ -35,6 +30,18 @@ pub fn abort_on_panic() {
}));
}

/// Set up a tracing subscriber.
///
/// Use `RUST_LOG=info` to see the logs in testing.
pub fn init_tracing() {
let _ = tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_test_writer()
.with_ansi(std::env::var("NO_COLOR").is_err() && std::io::stdout().is_terminal())
.with_line_number(true)
.try_init();
}

/// Guard which has to be dropped before timeout is reached.
/// Otherwise the test will panic.
#[allow(dead_code)]
Expand Down

0 comments on commit 1dbe86b

Please sign in to comment.